从邮件中打开自定义文件后会调用哪种方法

发布于 2025-01-06 03:33:44 字数 1546 浏览 1 评论 0原文

简短版本:

当我退出应用程序(主页按钮)时,UIApplicationExitsOnSuspend 设置为 NO,并打开一个从 Mail 到我的应用程序的自定义文件,调用了 UIViewController 的哪个方法?

或者,如何使我的 AppDelegate 成为 rootViewController 的 -performSegueWithIdentifier ?这段代码安全吗?

UIViewController *vc = [self.window.rootViewController.childViewControllers objectAtIndex:0];
[vc performSegueWithIdentifier:@"ChiesaSegue" sender:vc];

更多详细信息:

我的应用程序带有故事板“嵌入”一个带有两个不同导航控制器 >UIViewControllers,假设 FirstVCSecondVC 通过适当的 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 后,会调用 FirstVCSecondVC 的哪个方法!我正在清理旧数据并在 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2025-01-13 03:33:44

从后台返回时,完全有可能不会调用任何视图控制器 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文