从URL和Pass Parameters打开iOS应用程序 [英] Open iOS app from URL AND Pass Parameters

查看:96
本文介绍了从URL和Pass Parameters打开iOS应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接应该打开应用程序。我有这个工作。我只是想知道如何传递参数。假设网址是addappt://?code = abc。弹出视图控制器时,代码字段应填充文本 - 等于符号后的字母。我有部分工作要做。我使用以下(在app delegate.m中)

A link should open the app. I've got that to work. I just want to know how to pass a parameter. Let's say the url is "addappt://?code=abc". When a view controller pops up, a code field should have populated text - the letters after the equals to sign. I've got part of this to work. I use the following (in app delegate.m):

NSArray *elements = [url.query componentsSeparatedByString:@"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
          val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

(BTW:val在appdelegate.h中声明

(BTW: val is declared in appdelegate.h

我也可以将 val 传递给视图控制器。我唯一的问题是填充文本字段,名为'code'。如果通过链接打开应用程序,您如何填写代码?

I am also able to pass val to the view controller. My only problem is populating the textfield, named 'code'. How can you populate code as soon as the app is opened by the link?

帮助感谢。

推荐答案

这是关于在iOS中使用自定义URL方案

在教程中,您应该解析URL参数并存储它们在此方法中在应用程序中使用:

As in the tutorial, you should parse the URL parameters and store them to use in the app in this method:

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

这篇关于从URL和Pass Parameters打开iOS应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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