您的位置:首页 > 其它

极光推送

2016-05-17 21:42 169 查看
//APP启动,通知处理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {

//清除所有的通知
[APService
clearAllLocalNotifications];

    //JPush
#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];
}

- (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.
    [[UIApplication
sharedApplication] setApplicationIconBadgeNumber:0];
    [APService
resetBadge];
}

- (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.
    [application setApplicationIconBadgeNumber:0];
    [APService
resetBadge];
}
//JPush
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData
*)deviceToken {
    
    // Required
    [APService
registerDeviceToken:deviceToken];
    NSLog(@"deviceToken : %@",deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError
*)error {
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo {
    // Required
    [APService
handleRemoteNotification:userInfo];
    NSLog(@"收到通知",
);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary
*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
      //NSLog(@"application.applicationState =%d",application.applicationState);
    if (userInfo) {
        [APService
handleRemoteNotification:userInfo];
    }
    completionHandler(UIBackgroundFetchResultNewData);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: