我想从推送通知消息中获取数据。app在前台和后台都能成功获取数据。但我无法获得数据时,应用程序是退出和用户按下查看按钮的推送通知。我在应用程序中写的代码确实完成了启动。此代码导致应用程序在按下推送通知消息的查看按钮时崩溃。如果我注释代码,那么应用程序就不会崩溃。请帮助我从推送通知获取数据时,应用程序是退出和用户按下查看按钮的推送通知。我真的很感激。
if(launchOptions != nil){
NSDictionary *tmpDic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (tmpDic!=nil) {
pushedMessage=[NSString stringWithFormat:@"%@",[[tmpDic objectForKey:@"aps"] objectForKey:@"alert"]];
pushedCountry=[NSString stringWithFormat:@"%@",[tmpDic objectForKey:@"country"]];
[self saveToDatabase];
}
}发布于 2012-07-18 19:50:44
当您单击查看按钮时
- (void)application:(UIApplication*)application didReceiveRemoteNotification: (NSDictionary*)userInfo
{
}调用此方法后,userinfo将包含所有数据
在didReceiveRemoteNotification:中,您在didfinishlaunch方法中执行的操作
发布于 2015-03-21 15:32:25
请试试这个。
将此代码添加到appdelegate.m => didFinishLaunchingWithOptions
if ([launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]) {
[self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
}发布于 2015-05-08 19:39:37
在ios7中,我们使用下面的委托方法来处理应用程序处于后台或未运行时的推送通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler https://stackoverflow.com/questions/10651383
复制相似问题