gpt4 book ai didi

ios - "Open with..."问题,如果应用程序尚未打开

转载 作者:可可西里 更新时间:2023-11-01 05:37:01 26 4
gpt4 key购买 nike

我的应用程序可以读取使用“打开方式...”对话框打开的 .txt 文件。我在

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法。

有趣的是,它似乎只有在该应用程序之前已打开时才有效。如果我在即邮件中打开一个 .txt 文件并选择“打开方式”,那么我的应用程序。我可以在控制台中看到,

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

被调用。我还可以看到应该在

中的正确文件的 URL

file://localhost/private/var/mobile/Applications/F15C57D0-4F62-4979-943A-2D387488D59C/Documents/Inbox/myFile.txt

但是当我尝试打开文件时,我收到一个 Cocoa 错误,指出文件不存在。

如果我重复这些步骤(在后台打开应用程序的情况下),则会找到文件并立即运行。这是为什么?

最佳答案

您应该只在 application:openUrl:sourceApplication:annotations 中处理这种情况。根据文档(https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:openURL:sourceApplication:annotation:):

If your app had to be launched to open the URL, the app calls the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods first, followed by this method. The return values of those methods can be used to prevent this method from being called. (If the app is already running, only this method is called.)

因此,不再需要在 application:didFinishLaunchingWithOptions: 中处理打开文件。

关于ios - "Open with..."问题,如果应用程序尚未打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14940178/

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