从 URL 和传递参数打开 iOS 应用程序 [英] Open iOS app from URL AND Pass Parameters
问题描述
一个链接应该可以打开应用.我有这个工作.我只想知道如何传递参数.假设 url 是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];
(顺便说一句: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 Scheme
在教程中,您应该解析 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 和传递参数打开 iOS 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!