2015-11-04 167 views
1

我正面临着这个奇怪的问题。我有一段简单的代码应该可以正常工作,但在第一次启动应用程序时它不起作用。当我第二次运行应用程序时,它工作得很好。当第一次启动应用程序时,presentViewController不起作用

和由以下代码用于打开应用程序,并显示一个的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

从上面你为什么需要首次使用handleOpenURL来启动应用程序? – user3182143

+0

当我点击今日视图部件时,我正在使用它来打开应用程序。 – user3687

+0

我在问你为什么把你的代码放在handleOpenURL方法中? – user3182143

回答

0

尝试这种情况:

  • (BOOL)应用: (UIApplication的*)应用handleOpenURL:(NSURL *)的url

{

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(1 * NSEC_PER_SEC)),dispatch_get_main_queue(),^ {[NSNotificationCenter defaultCenter] postNotificationName:@“secondshowPushNotification”object:nil]; });

}

的firstView控制器:

  • (无效)viewDidLoad中

{

[[NSNotificationCenter defaultCenter]的addObserver:自选择器:@selector(showCompanyFromPushNotification :)名:@“secondshowPushNotification”object:nil];

}

- (无效)showCompanyFromPushNotification:(NSNotification *)通知

{

[self.rootController presentViewController:secondViewController动画:YES完成:无];

}

//它打开secondViewController。

相关问题