极光推送

来源:互联网 发布:淘宝app我的分享在哪里 编辑:程序博客网 时间:2024/04/30 05:00

//APP启动,通知处理

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

//清除所有的通知

[APServiceclearAllLocalNotifications];

    //JPush

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1

    if ([[UIDevicecurrentDevice].systemVersionfloatValue] >= 8.0) {

        //可以添加自定义categories

        [APServiceregisterForRemoteNotificationTypes:(UIUserNotificationTypeBadge |

                                                      UIUserNotificationTypeSound |

                                                      UIUserNotificationTypeAlert)

                                           categories:nil];

    } else {

        //categories 必须为nil

        [APServiceregisterForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

                                                      UIRemoteNotificationTypeSound |

                                                      UIRemoteNotificationTypeAlert)

                                           categories:nil];

    }

#else

    //categories 必须为nil

    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |

                                                   UIRemoteNotificationTypeSound |

                                                   UIRemoteNotificationTypeAlert)

                                       categories:nil];

#endif

    // Required

    [APServicesetupWithOption: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.

    [[UIApplicationsharedApplication] setApplicationIconBadgeNumber:0];

    [APServiceresetBadge];

}


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

    [APServiceresetBadge];

}

//JPush

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

    

    // Required

    [APServiceregisterDeviceToken: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

    [APServicehandleRemoteNotification:userInfo];

    NSLog(@"收到通知",);

}


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

      //NSLog(@"application.applicationState =%d",application.applicationState);

    if (userInfo) {

        [APServicehandleRemoteNotification:userInfo];

    }

    completionHandler(UIBackgroundFetchResultNewData);

}



0 0
原创粉丝点击