我正面临这个奇怪的问题。我有一段简单的代码可以正常工作,但在第一次启动应用程序时它不起作用。当我第二次运行应用程序时,它完全正常。
顺便说一下,当我点击今天的视图小部件时,使用以下代码打开应用程序并显示viewController:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
OverviewDetailVC *overViewDetail = (OverviewDetailVC *)initViewController;
overViewDetail.productDetail = [self.managedObjectContext executeFetchRequest:FetchRequest error:nil];
overViewDetail.productName = [overViewDetail.productDetail[0] valueForKey:@"generic"];
[self.window.rootViewController presentViewController:overViewDetail animated:YES completion:NULL];
}
答案 0 :(得分:0)
试试这个:
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1 * NSEC_PER_SEC)),dispatch_get_main_queue(),^ { [[NSNotificationCenter defaultCenter] postNotificationName:@“secondshowPushNotification”对象:nil]; });
}
FirstView控制器:
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showCompanyFromPushNotification :) name:@“secondshowPushNotification”object:nil];
}
- (无效)showCompanyFromPushNotification:(NSNotification *)通知
{
[self.rootController presentViewController:secondViewController animated:YES completion:nil];
}
//打开第二个ViewController。