我正在尝试在应用关闭时连接通知。我需要从APNS收到一条消息并通过id打开所需的文章。问题是APF函数didFinishLaunchingWithOptions中没有读取消息。我不知道哪里出错了。我试图解析(NSDictionary *)launchOptions并提取文章的ID。在函数内部 - didReceiveRemoteNotification一切正常。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self settingMenuNotification];
[self restKitConfiguration];
[self registerSettingsAndCategories];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@",[paths objectAtIndex:0]);
if(launchOptions != NULL) {
NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
[self openNewsDetailNotification:apsInfo];
}
return YES;
}
-(void) openNewsDetailNotification:(NSDictionary*)apsInfo {
if( [apsInfo objectForKey:@"id"] != NULL) { //id - id_article
NSString *id_article = [apsInfo objectForKey:@"id"];
NSNumber *objectId = [NSNumber numberWithInteger: [id_article integerValue]];
NSLog(@"Получил id %@", id_article);
// Загружаем статью
UIWindow *window=[UIApplication sharedApplication].keyWindow;
UIViewController *root = [window rootViewController];
UIStoryboard *storyboard = root.storyboard;
NewsDetailViewController *newsVC = (NewsDetailViewController*)[storyboard instantiateViewControllerWithIdentifier:@"NewsDetailViewController"];
newsVC.objectId = objectId;
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
[navController.visibleViewController.navigationController pushViewController:newsVC animated:YES];
}
}
答案 0 :(得分:1)
同样的事情发生在我身上。我在这方面增加了延迟。使用此代码而不是直接调用该函数。
[self performSelector:@selector(openNewsDetailNotification:) withObject:apsInfo afterDelay:6.0f];