简体   繁体   English

当应用程序使用URL方案在iOS中打开我的应用程序时,如何获取呼叫者的信息

[英]How to get the caller's info When a app using URL Scheme to open my App in iOS

In my situation, a third-party app will using URL Scheme to open my App in iOS, but my App must get some information about the caller, like caller's app name, caller's app icon. 在我的情况下,第三方应用程序将使用URL Scheme在iOS中打开我的应用程序,但是我的应用程序必须获取有关呼叫者的一些信息,例如呼叫者的应用名称,呼叫者的应用图标。

How to do this ? 这个怎么做 ? or Is there another way to solve the situation? 还是有解决问题的另一种方法?

If you implement openURL in your AppDelegate , you can get some of those value, app icon is not possible though, you have to prepare it yourself or the scheme must somehow have it as url/data: 如果在AppDelegate实现openURL ,则可以获取其中一些值,但是无法显示应用程序图标,您必须自己准备它,或者该方案必须以某种方式将其作为url / data:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
        print("source \(sourceApplication)")
        print("scheme \(url.scheme)")
        print("query \(url.query)")
        print("full \(url.absoluteString)")
}

iOS can bind your app and a custom URL Scheme. iOS可以绑定您的应用程序和自定义URL方案。 With this URL Scheme you can 使用此URL方案,您可以
launch your app from browser or other app. 从浏览器或其他应用程序启动您的应用程序。

在此处输入图片说明

You create the URL Scheme like snapshot: 您创建类似于快照的URL方案:

URL Scheme: myapp
URL identifier: com.ypd.myapp

Then you can send URL like this below: 然后,您可以按照以下方式发送网址:

myapp://
myapp://example/path/here
myapp://?param1=1&param2=2
myapp://some/path/here?param1=1&param2=2

From the delegate method, you can get the deliver data: 从委托方法中,您可以获取传递数据:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url   
{  
    // Do something with the url here  
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM