极光推送

来源:互联网 发布:炫踪网络 ceo 编辑:程序博客网 时间:2024/04/27 20:21
<span style="font-size:18px;">////  JPushHelper.m//  LJEJPushDemo////  Created by xiaoyao on 14/11/22.//  Copyright (c) 2014年 lijien. All rights reserved.//#import "JPushHelper.h"#import "APService.h"@implementation JPushHelper+ (void)setupWithOptions:(NSDictionary *)launchingOptions {  #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {    // 自定义类型    [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge|                                                   UIUserNotificationTypeAlert|                                                   UIUserNotificationTypeSound)                                       categories:nil];  } else {    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|                                                   UIRemoteNotificationTypeAlert|                                                   UIRemoteNotificationTypeSound)                                       categories:nil];  }  #else    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|                                                 UIRemoteNotificationTypeAlert|                                                 UIRemoteNotificationTypeSound)                                     categories:nil];#endif  // required 启动注册的推送消息  [APService setupWithOption:launchingOptions];}+(void)registerDeviceToken:(NSData *)deviceToken {  [APService registerDeviceToken:deviceToken];}+(void)handleRemoteNotification:(NSDictionary *)remoteInfo completion:(pushComletion)completion {  [APService handleRemoteNotification:remoteInfo];    if (completion) {    completion(UIBackgroundFetchResultNewData);  }    return;}+(void)showLocalNotification:(UILocalNotification *)localNotification {  [APService showLocalNotificationAtFront:localNotification identifierKey:nil];    return;}@end////  AppDelegate.m//  LJEJPushDemo////  Created by xiaoyao on 14/11/22.//  Copyright (c) 2014年 lijien. All rights reserved.//#import "AppDelegate.h"#import "JPushHelper.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  [JPushHelper setupWithOptions:launchOptions];  // Override point for customization after application launch.  self.window.backgroundColor = [UIColor whiteColor];  [self.window makeKeyAndVisible];  return YES;}- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {  [JPushHelper registerDeviceToken:deviceToken];    return;}// 收到推送的消息- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {  [JPushHelper handleRemoteNotification:userInfo completion:nil];    return;}#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {  [JPushHelper handleRemoteNotification:userInfo completion:completionHandler];    // 当应用程序处于前台的时候则需我们手动处理本地消息  if (application.applicationState == UIApplicationStateActive) {    UIAlertView *msgAlertView = [[UIAlertView alloc] initWithTitle:@"推送消息"                                                           message:userInfo[@"aps"][@"alert"]                                                          delegate:self                                                 cancelButtonTitle:@"取消"                                                 otherButtonTitles:@"确定", nil];    [msgAlertView show];  }}#endif- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {  [JPushHelper showLocalNotification:notification];    return;}- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {  NSLog(@"Error in registration. Error: %@", err);}- (void)applicationDidBecomeActive:(UIApplication *)application {  [application setApplicationIconBadgeNumber:0];    return;}- (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.}- (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)applicationWillTerminate:(UIApplication *)application {  // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end</span>

0 0
原创粉丝点击