I’m making an app using a custom URL scheme, so I thought I’d share it with everyone else incase they were curious.
Step 1 Go into your app’s info.plst file.
Step 2 Add a Row to this and call it “URL types”
Step 3 Expand the first item in “URL types” and add a row called “URL identifier”, the value of this string should be the reverse domain for your app e.g. “com.yourcompany.myapp”.
Step 4 Again, add a row into the first item in “URL types” and call it “URL Schemes”
Step 5 Inside “URL Schemes” you can use each item as a different url you wish to use, so if you wanted to use “myapp://“ you would create an item called “myapp”.
After all of this, your structure should look something like this:
Using the URL Scheme Now you’ve registered the URL with the app, you can start the application by opening a url with the custom scheme.
This url will send a message to the UIApplicationDelegate so if you want to provide a custom handler for it, all you need to do is provide an implementation for it in your delegate.
Something like this:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { // Do something with the url here }
Most people will want to parse the URL and store it in the NSUserDefaults, here is a example of how you could do that:
近期评论