AppDelegate 的 application:openURL:options: 方法中的选项参数是什么?
What is the options argument in the AppDelegate's application:openURL:options: method?
我在网上搜索了一圈又一圈也没找到一个例子。 Apple 的文档说它是定义启动选项。但这些是什么?要包含的 harmless/basic 选项是什么?
From the Apple docs on UIApplicationDelegate
:
Open a URL that was sent to your app. If there is a URL to open, the system calls the application:openURL:options: method of your app delegate. You can also tell if there is a URL to open by looking in the launch options dictionary for the UIApplicationLaunchOptionsURLKey key.
因此,options 参数是供系统提供的,当您的应用程序打开时,已发送给它的URL。 调用它时不必传递任何内容,因此如果您只是使用它打开外部 URL(尽管您可能想要为 UIApplicationLaunchOptionsSourceApplicationKey
密钥传递您的包 ID)。
编辑
进一步考虑,这完全是从您的应用程序打开外部 URL 的错误方式。它只是系统调用的委托方法,以允许您的应用程序打开 URL(例如来自 Safari 操作 sheet)。你想要:
[[UIApplication sharedApplication] openURL:url];
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsSourceApplicationKey | NSString containing the bundle ID of the originating application |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsAnnotationKey | property-list typed object corresponding to what the originating application passed in UIDocumentInteractionController's annotation property |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsOpenInPlaceKey | bool NSNumber, set to YES if the file needs to be copied before use |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
我在这里提供了一个类似问题的答案:
我在网上搜索了一圈又一圈也没找到一个例子。 Apple 的文档说它是定义启动选项。但这些是什么?要包含的 harmless/basic 选项是什么?
From the Apple docs on UIApplicationDelegate
:
Open a URL that was sent to your app. If there is a URL to open, the system calls the application:openURL:options: method of your app delegate. You can also tell if there is a URL to open by looking in the launch options dictionary for the UIApplicationLaunchOptionsURLKey key.
因此,options 参数是供系统提供的,当您的应用程序打开时,已发送给它的URL。 调用它时不必传递任何内容,因此如果您只是使用它打开外部 URL(尽管您可能想要为 UIApplicationLaunchOptionsSourceApplicationKey
密钥传递您的包 ID)。
编辑
进一步考虑,这完全是从您的应用程序打开外部 URL 的错误方式。它只是系统调用的委托方法,以允许您的应用程序打开 URL(例如来自 Safari 操作 sheet)。你想要:
[[UIApplication sharedApplication] openURL:url];
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsSourceApplicationKey | NSString containing the bundle ID of the originating application |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsAnnotationKey | property-list typed object corresponding to what the originating application passed in UIDocumentInteractionController's annotation property |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
| UIApplicationOpenURLOptionsOpenInPlaceKey | bool NSNumber, set to YES if the file needs to be copied before use |
+-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------+
我在这里提供了一个类似问题的答案: