恢复应用程序时获取launchOptions [英] Get launchOptions when resuming App

查看:27
本文介绍了恢复应用程序时获取launchOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在 application 方法中处理launchOptions值(显然,因为参数已传递给它).我所做的基本上是从在 Share 菜单中选择我的应用的用户从导入图像的用户那里接收图像:

I am able to handle the launchOptions value in the application method (since, obviously, the parameter gets passed to it). What I'm doing is basically receiving an image from a user who imported it by selecting my app in the Share menu:

如果尚未启动该应用程序,则可以正常工作,但是如果该应用程序已在运行且未调用 application 方法,我看不到如何获取输入参数.

It works fine if the App hasn't already been launched, but I don't see how I get the input parameters if the App is already running and the application method isn't called.

我试图找到一种可以帮助我的方法

I tried to find a method that would help me like

applicationWillEnterForeGround(_ application:UIApplication,_ launchOptions:[UIApplicationLaunchOptionsKey:Any]?

但没有成功.

我认为这是有可能的,因为即使它们已经启动,您也可以将图像共享到WhatsApp或Facebook.

I assume it's possible, since you can share images to WhatsApp or Facebook too, even when they've already been launched.

有人可以帮我吗?

谢谢,扬

推荐答案

您应按以下方式实现 application:openURL:options:方法(Swift 2):

You should implement the application:openURL:options: method as follows (Swift 2):

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    // Do your stuff and return true if you have handled the URL...

    // Else
    return false
}

Ray Wenderlich中的相关教程

从Swift 4.2开始,签名为:

As of Swift 4.2 the signature is:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    // Do your stuff and return true if you have handled the URL...

    // Else
    return false
}

这篇关于恢复应用程序时获取launchOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆