本文共 2145 字,大约阅读时间需要 7 分钟。
极光推送比较简单,只需要将官方sdk中的lib集成到程序中,配置相应的系统静态库就差不多了。。
还有一个plist文件配置
额。。。 还有证书和配置文件导入
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Required #ifdef __IPHONE_8_0 if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { //可以添加自定义categories [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; } else { //categories 必须为nil [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil]; } #endif // Required [JPUSHService setupWithOption:launchOptions appKey:@"1a2e5ac086dcb10de4136846" channel:@"0" apsForProduction:FALSE]; //如需兼容旧版本的方式,请继续使用[JPUSHService setupWithOption:launchOptions]初始化方法和添加pushConfig.plist文件声明AppKey等配置内容。}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required [JPUSHService registerDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { //Optional NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { // Required,For systems with less than or equal to iOS6 [JPUSHService handleRemoteNotification:userInfo]; NSLog(@"%@",userInfo); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // 应用正处理前台状态下,不会收到推送消息,因此在此处需要额外处理一下 if (application.applicationState == UIApplicationStateActive) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收到推送消息" message:userInfo[@"aps"][@"alert"] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alert show]; } // IOS 7 Support Required [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); NSLog(@"%@",userInfo); }转载地址:http://ekovi.baihongyu.com/