大佬教程收集整理的这篇文章主要介绍了ios – UIApplicationLaunchOptionsRemoteNotificationKey没有获取userinfo,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
编辑:
如果您希望调用推送通知(通过后台获取,当您的应用程序未处于活动状态时),您需要让后端开发人员在推送通知中设置“content-available”:1.
之后-application:didReceiveRemoteNotification:fetchCompletionHandler:将被调用(当推送通知到达时),因此您可以将有效负载保存到文件中,然后当应用程序打开时,您可以读取文件并执行操作.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBACkgroundFetchResult))completionHandler { NSLog(@"#BACKGROUND FETCH CALLED: %@",userInfo); // When we get a push,just wriTing it to file NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *documentsDirectory = [paths objectATindex:0]; NSString *filePath = [documentsDirectory StringByAppendingPathComponent:@"userInfo.plist"]; [userInfo writeToFile:filePath atomically:YES]; completionHandler(UIBACkgroundFetchResultNewData); } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // checking if application was launched by tapping icon,or push notification if (!launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES); NSString *documentsDirectory = [paths objectATindex:0]; NSString *filePath = [documentsDirectory StringByAppendingPathComponent:@"userInfo.plist"]; [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; NSDictionary *info = [NSDictionary DictionaryWithContentsOfFile:filePath]; if (info) { // Launched by tapping icon // ... your handling here } } else { NSDictionary *info = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; // Launched with swiping // ... your handling here } return YES; }
以上是大佬教程为你收集整理的ios – UIApplicationLaunchOptionsRemoteNotificationKey没有获取userinfo全部内容,希望文章能够帮你解决ios – UIApplicationLaunchOptionsRemoteNotificationKey没有获取userinfo所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。