极光推送的配置4(1-5)

xcode中代码的配置:Appdelegate中的代码

#import "AppDelegate.h"

#import "APService.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

{

NSMutableArray * arr;

}

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

// Override point for customization after application launch.

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

self.window.backgroundColor = [UIColor whiteColor];

ViewController * rootView = [[ViewController alloc]init];

self.window.rootViewController = rootView;

[self.window makeKeyAndVisible];

// Required

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

}

// Required

[APService setupWithOption:launchOptions];

//NSNotificationCenter的这个为极光的自定义推送内容  即为本地推送,用远程推送的话 这个可不写

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];

return YES;

}

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

// Required

arr = [NSMutableArray array];

[APService registerDeviceToken:deviceToken];

NSLog(@" arr :%lu  deviceToken : %@",(unsigned long)arr.count,deviceToken);

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

// Required

[APService handleRemoteNotification:userInfo];

}

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

// IOS 7 Support Required

[APService handleRemoteNotification:userInfo];

completionHandler(UIBackgroundFetchResultNewData);

NSLog(@"userInfo %@",userInfo);

}

//打印出现的错误

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{

NSLog(@"error :%@",error);

}

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

//在你收到通知消息时,图标位置会显示小光标  这行代码是打开app应用时,让那些数字消失

[[UIApplication sharedApplication] 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.

}

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

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 如果app需要开启远程推送功能,自己写下来就会相对较麻烦,所以我选择了极光推送 一.证书下载 这里的证书,是创建开...
    iOS_July阅读 3,203评论 0 0
  • 此处我用的是jpush-react-native,这个是极光官网维护的,还有一个是react-antive-jpu...
    liu_520阅读 24,445评论 95 39
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,599评论 5 6
  • 这世上最暖心也是最心寒的事就是闺蜜间的竞争和慰藉 考验什么也不要考验人性。这是看完这本书后最深刻的体会。 书的封面...
    更欣阅读 2,325评论 0 15
  • 暮秋的萧瑟侵染了田陌 留下木叶尽脱柿树在翘望 翘望一个耄耋的身影 我襁褓中的两段记忆 一段是母亲慈祥的面庞 一段是...
    月圆天心阅读 2,118评论 0 0

友情链接更多精彩内容