NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];解决方法 您无法检测到这种情况,因为应用程序未使用推送通知打开(它已通过应用程序图标打开).
尝试通过滑动推送通知打开应用程序.
编辑:
如果您希望调用推送通知(通过后台获取,当您的应用程序未处于活动状态时),您需要让后端开发人员在推送通知中设置“content-available”:1.
之后-application:dIDReceiveRemoteNotification:fetchCompletionHandler:将被调用(当推送通知到达时),因此您可以将有效负载保存到文件中,然后当应用程序打开时,您可以读取文件并执行 *** 作.
- (voID)application:(UIApplication *)applicationdIDReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(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 tap@R_301_6817@ 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 tap@R_301_6817@ icon // ... your handling here } } else { NSDictionary *info = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; // Launched with swi@R_301_6817@ // ... your handling here } return YES;}
另外,不要忘记在“后台模式”中启用“远程通知”
总结以上是内存溢出为你收集整理的ios – UIApplicationLaunchOptionsRemoteNotificationKey没有获取userinfo全部内容,希望文章能够帮你解决ios – UIApplicationLaunchOptionsRemoteNotificationKey没有获取userinfo所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)