gpt4 book ai didi

ios - 应用程序关闭时 didFinishLaunchingWithOptions APNS

转载 作者:行者123 更新时间:2023-11-29 01:26:16 25 4
gpt4 key购买 nike

我正在尝试在应用关闭时连接通知。我需要从 APNS 获取消息并通过 id 打开所需的文章。问题是消息没有被 APNS 在函数 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];
}
}

最佳答案

我也遇到了同样的情况。我在其中添加了延迟。使用此代码而不是直接调用该函数。

            [self performSelector:@selector(openNewsDetailNotification:) withObject:apsInfo afterDelay:6.0f];

关于ios - 应用程序关闭时 didFinishLaunchingWithOptions APNS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33981218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com