《iOS极光推送步骤》

1.https://www.jpush.cn/极光网创建新的应用《iOS极光推送步骤》_第1张图片

2.https://developer.apple.com苹果开发者网站<1>钥匙串创建证书请求、<2>申请开发者证书、<3>创建APPID、<4>申请provision文件。。。。。<5>钥匙串创建证书请求、<6>创建APNS推送通知证书。

3.APNS推送通知证书导出p12文件,上传到极光网(开发环境: 已验证)表示证书上传成功。

4.创建配置PushConfig.plist文件,修改info.plist的Bundle identifier与苹果开发者网站上APPID一致。


《iOS极光推送步骤》_第2张图片

《iOS极光推送步骤》_第3张图片


4代码集成

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

    

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

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    

    //————————————————点击远程推送通知消息进入APP——————————————//

    NSLog(@"_________launchOptions_________ = %@",launchOptions);

    if (launchOptions) {

        

        NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

        _userInfo = userInfo;

//        [self presentViewControllerWithUserInfo:userInfo];

//        NSLog(@">>>launchOptions.message<<<< = %@",[launchOptions objectForKey:@"message"]);

        

    }

    

    

    ————————————————————极光推送Required————————————————————

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

    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];

    }

#else

    //categories 必须为nil

    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

                                                   UIRemoteNotificationTypeSound |

                                                   UIRemoteNotificationTypeAlert)

                                       categories:nil];

#endif

    // Required

    [APService setupWithOption:launchOptions];

    

    

    

    

    self.window.rootViewController = [[TabBarViewController alloc] init];

    

    return YES;

}

#pragma mark - 消息跳转页面

- (void)presentViewControllerWithUserInfo:(NSDictionary *)userInfo {

    

    //拿出消息内容,跳转即可~~~~

    _userInfo = userInfo;

    UIAlertView *remoteNotification = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的安装视频通过审核,请点击确定进入一键激活" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    [remoteNotification show];

    

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    

    if (buttonIndex == 0) {

        UIStoryboard *fafangStoryboard = [UIStoryboard storyboardWithName:@"FaFang" bundle:nil];

        LFNavigationViewController *lfVC = [fafangStoryboard instantiateViewControllerWithIdentifier:@"LFNavigationViewController"];

        

        NSLog(@"&&&&&%@&&&&&&",lfVC);

        

        BluetoothViewController *blueVC = [fafangStoryboard instantiateViewControllerWithIdentifier:@"BluetoothViewController"];

        blueVC.userInfo = _userInfo;

        [self.window.rootViewController presentViewController:lfVC animated:YES completion:nil];

        [lfVC pushViewController:blueVC animated:YES];

        

    }

    

}


- (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.

    

    [application 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.

    

    [application setApplicationIconBadgeNumber:0];

    [application cancelAllLocalNotifications];

    

}


- (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:.

}



#pragma mark - 极光推送

/*************极光推送****************/



- (void)application:(UIApplication *)application

didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    

    NSLog(@"%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);

    [APService registerDeviceToken:deviceToken];

    NSLog(@"APService registrationID:%@",[APService registrationID]);

    

    

    

    /*

     设置 设置别名(alias)与标签(tags

     别名 alias每个用户只能指定一个别名

     标签 tag可为每个用户打多个标签

     */

    [APService setTags:[NSSet setWithObjects:@"tag1",nil] alias:@"testOBU-0000000" callbackSelector:@selector(tagsAliasCallback:tags:alias:) target:self];

}

//设置别名(alias)与标签(tags)回掉函数。

- (void)tagsAliasCallback:(int)iResCode

                     tags:(NSSet *)tags

                    alias:(NSString *)alias {

    

    

    NSLog(@"iResCode = %d,tags = %@服务器返回的结果:%@",iResCode,tags,alias);

    

}


- (void)application:(UIApplication *)application

didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);

}


//- (void)tagsAliasCallback:(int)iResCode tags:(NSSet*)tags alias:(NSString*)alias {

//    NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, tags , alias);

//}


#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

- (void)application:(UIApplication *)application

didRegisterUserNotificationSettings:

(UIUserNotificationSettings *)notificationSettings {

}


// Called when your app has been activated by the user selecting an action from

// a local notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication *)application

handleActionWithIdentifier:(NSString *)identifier

forLocalNotification:(UILocalNotification *)notification

  completionHandler:(void (^)())completionHandler {

}


// Called when your app has been activated by the user selecting an action from

// a remote notification.

// A nil action identifier indicates the default action.

// You should call the completion handler as soon as you've finished handling

// the action.

- (void)application:(UIApplication *)application

handleActionWithIdentifier:(NSString *)identifier

forRemoteNotification:(NSDictionary *)userInfo

  completionHandler:(void (^)())completionHandler {

}

#endif


//————————————APP正在前台或者后台运行,此函数会被调用————————————//

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo {

    [APService handleRemoteNotification:userInfo];

    NSLog(@":+++++++收到通知+++++++:%@", [self logDic:userInfo]);

    // [rootViewController addNotificationCount];

    

    /*

    if (application.applicationState != UIApplicationStateActive) {

        [self presentViewControllerWithUserInfo:userInfo];

    }

     */

    

}


//————————————APP正在前台或者后台运行,此函数会被调用————————————//

- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

fetchCompletionHandler:

(void (^)(UIBackgroundFetchResult))completionHandler {

    [APService handleRemoteNotification:userInfo];

    NSLog(@">>>>>>收到通知<<<<<<:%@", [self logDic:userInfo]);

    //   [rootViewController addNotificationCount];

    

    completionHandler(UIBackgroundFetchResultNewData);

    

    

    if (application.applicationState != UIApplicationStateActive) {

        [self presentViewControllerWithUserInfo:userInfo];

    }

}




// log NSSet with UTF8

// if not ,log will be \Uxxx

- (NSString *)logDic:(NSDictionary *)dic {

    if (![dic count]) {

        return nil;

    }

    NSString *tempStr1 =

    [[dic description] stringByReplacingOccurrencesOfString:@"\\u"

                                                 withString:@"\\U"];

    NSString *tempStr2 =

    [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

    NSString *tempStr3 =

    [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];

    NSString *str =

    [NSPropertyListSerialization propertyListFromData:tempData

                                     mutabilityOption:NSPropertyListImmutable

                                               format:NULL

                                     errorDescription:NULL];

    return str;

}





- (void)viewWillAppear:(BOOL)animated {

    

    [APService startLogPageView:@"PageOne"];

    

}

- (void)viewWillDisappear:(BOOL)animated {

    

    [APService stopLogPageView:@"PageOne"];

}

//(void)trackView {

//    

//    [APService beginLogPageView:@"PageTwo" duration:10];

//}




你可能感兴趣的:(《iOS开发之路》)