Open iOS app from URL AND Pass Parameters

人走茶凉 提交于 2019-11-30 06:57:20

问题


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 is declared in appdelegate.h

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?

Help Appreciated.


回答1:


Here is a nice tutorial on Using Custom URL Scheme in iOS

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
}


来源:https://stackoverflow.com/questions/14227288/open-ios-app-from-url-and-pass-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!