从邮件中打开自定义文件后会调用哪种方法
简短版本:
当我退出应用程序(主页按钮)时,UIApplicationExitsOnSuspend
设置为 NO
,并打开一个从 Mail 到我的应用程序的自定义文件,调用了 UIViewController 的哪个方法?
或者,如何使我的 AppDelegate
成为 rootViewController 的 -performSegueWithIdentifier
?这段代码安全吗?
UIViewController *vc = [self.window.rootViewController.childViewControllers objectAtIndex:0];
[vc performSegueWithIdentifier:@"ChiesaSegue" sender:vc];
更多详细信息:
我的应用程序带有故事板“嵌入”一个带有两个不同的导航控制器 >UIViewControllers
,假设 FirstVC
和 SecondVC
通过适当的 Segues 连接在一起。我通过设置 info.plist 文件将自定义文件扩展名(例如 .q80)与我的应用程序相关联,并且我可以看到我的自定义文件与我的应用程序一起显示邮件中的图标。所有这些都工作得很好。
我关闭应用程序(主页按钮),然后转到邮件,然后“在...中打开”文件,应用程序打开,我在AppDelegate
中正确处理传入的URL现在
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
,我希望能够在我的 SecondVC
中加载此导入 URL 的数据,但是每次我“打开于..” 文件时,我都会变旧数据完全按照我按下主页按钮时留下的方式返回。我不知道在 application:openURL:sourceApplication:annotation
中处理我的 URL 后,会调用 FirstVC
或 SecondVC
的哪个方法!我正在清理旧数据并在 -viewDidLoad
和 -viewWillAppear
中设置新数据。什么也没有发生!
如果您需要代码或我可能错过的其他详细信息,请告诉我。
Short Version:
When I exit the App (home button), UIApplicationExitsOnSuspend
is set to NO
, and open a custom file from Mail into my App, which method of a UIViewController
is invoked?
Alternatively, How do I make my AppDelegate
to -performSegueWithIdentifier
of my rootViewController? Is this code safe?
UIViewController *vc = [self.window.rootViewController.childViewControllers objectAtIndex:0];
[vc performSegueWithIdentifier:@"ChiesaSegue" sender:vc];
More Details:
I have got my App with storyboard "Embedded In" a Navigation Controller with two different UIViewControllers
, let's say FirstVC
and SencondVC
connected together with proper Segues. I have associated custom file extensions (let's say .q80) with my App by setting up my info.plist file, and I can see my custom file showing up with my App icon in Mail. All of this works perfectly fine.
I close the App (home button), and go to Mail, and "Open In.." a file, App opens up and I properly handle the incoming URL in AppDelegate
's
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
Now, I want to be able to load the data of this imported URL in my SecondVC
, however every time I "Open In.." a file I get old data back exactly the way I left it when I hit the home button. I don't know which method of FirstVC
or SecondVC
is invoked after my URL is processed in application:openURL:sourceApplication:annotation
! I am cleaning the old data and setting up the new data in -viewDidLoad
, and also -viewWillAppear
. Nothing happens!
Let me know if you need code, or other details I might have missed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从后台返回时,完全有可能不会调用任何视图控制器 viewWillLoad/Appear/etc 方法。如果您需要视图控制器中的某些行为基于 openURL 应用程序委托方法中的内容,那么您必须显式触发它。您可以使用 NSNotification 来实现此目的。或者,如果您的 openURL 方法正在修改某些应用程序模型状态,您可以在模型对象上使用键值观察。
It is entirely possible that none of the view controller viewWillLoad/Appear/etc methods will be called when returning from the background. If you need to some behavior in the view controllers based on things in the openURL application delegate method, then you have to trigger it explicitly. You could use a NSNotification for this purpose. Alternatively, if your openURL method is modifying some application model state, you could use key-value observing on your model objects.