美文网首页
极光推送的配置4(1-5)

极光推送的配置4(1-5)

作者: 我们的新世界 | 来源:发表于2016-02-01 14:47 被阅读72次

xcode中代码的配置:Appdelegate中的代码

#import "AppDelegate.h"

#import "APService.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

{

NSMutableArray * arr;

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.window.backgroundColor = [UIColor whiteColor];

ViewController * rootView = [[ViewController alloc]init];

self.window.rootViewController = rootView;

[self.window makeKeyAndVisible];

// Required

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

//可以添加自定义categories

[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

UIUserNotificationTypeSound |

UIUserNotificationTypeAlert)

categories:nil];

} else {

//categories 必须为nil

[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

UIRemoteNotificationTypeSound |

UIRemoteNotificationTypeAlert)

categories:nil];

}

// Required

[APService setupWithOption:launchOptions];

//NSNotificationCenter的这个为极光的自定义推送内容  即为本地推送,用远程推送的话 这个可不写

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];

return YES;

}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

// Required

arr = [NSMutableArray array];

[APService registerDeviceToken:deviceToken];

NSLog(@" arr :%lu  deviceToken : %@",(unsigned long)arr.count,deviceToken);

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

// Required

[APService handleRemoteNotification:userInfo];

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

// IOS 7 Support Required

[APService handleRemoteNotification:userInfo];

completionHandler(UIBackgroundFetchResultNewData);

NSLog(@"userInfo %@",userInfo);

}

//打印出现的错误

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

NSLog(@"error :%@",error);

}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

//在你收到通知消息时,图标位置会显示小光标  这行代码是打开app应用时,让那些数字消失

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end

相关文章

  • 极光推送的配置4(1-5)

    xcode中代码的配置:Appdelegate中的代码 #import "AppDelegate.h" #impo...

  • 极光推送(二)——推送的使用

    前言 在极光推送(一)——配置中讲过了极光推送的配置,这节讲讲极光推送的使用参考文档极光官网 下面以我写的demo...

  • 极光推送的配置1(1-5)

    IOS端的极光推送 首先在极光推送的官网 注册成为极光用户 之后点击创建应用 出现如下界面(图1) :应用名称是...

  • 极光推送的配置3(1-5)

    在xcode中的配置 图一 为导入的lib极光SDK和系统库 图2.1-2.3为创建PushConfig的pli...

  • 极光推送的配置2(1-5)

    配置证书 : 配置完图 一 图 二 的证书后 再配置图三的证书 配置时会出现下图的iOS development ...

  • 极光推送的配置5(1-5)

    极光推送配置过程中可能出现的问题: 1.当你的xcode在模拟器上运行时显示如下时,证明配置成功了 2.提示如下时...

  • 极光统计

    前言 极光统计可以独立使用,其配置和极光推送相似 极光统计配置 极光统计代码编写 极光统计方法调用 具体配置请参考...

  • iOS 极光推送诶配置成功却收不到推送消息的处理

    极光配置都OK了,推送能力打开了,Apple的推送证书也配置了,极光后台的推送证书也验证成功了,推送也打印了log...

  • 极光推送进行远程推送

    借阅:极光推送进行远程推送 怎么使用极光推送进行远程推送 在极光官网注册极光推送创建一个应用在应用配置中导入两个证...

  • iOS-iOS10极光推送的使用

    1、首先先配置好推送证书,传到极光。极光推送->iOS证书设置指南极光推送->iOS SDK集成指南(XCode8...

网友评论

      本文标题:极光推送的配置4(1-5)

      本文链接:https://www.haomeiwen.com/subject/bhuskttx.html