4

I've made a URL scheme in the Info.plist to call my app, but the URL also parses a string of data which I need to read.

After looking around for a little while I've found - http://www.informit.com/articles/article.aspx?p=2301787&seqNum=2

with the following code

var scheme: String!
var path: String!

var query: String!

func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {

  scheme = url.scheme
  path = url.path
  query = url.query

  return true
}

supposedly the function is called whenever I call the app through a URL, the function however is never called, and I can't imagine that I would have to put the function in the viewDidLoad, if I did put it in the viewDidLoad it would be called everytime the app started.

Am I wrong im presuming that - the function doesn't need to be called in the viewDidLoad or is there a better way to get data from a URL scheme using the Info.plist to create the scheme

5
  • 2
    this method is deprecated try to use - application:openURL:options: Commented Mar 16, 2016 at 9:58
  • 1
    I have written a step-by-step walkthrough of registering URL schemes (but in Objective-C), and this shows how to get the "application" function to get launched: mikesknowledgebase.com/pages/XCode/CustomURLs.htm Commented Mar 16, 2016 at 10:04
  • 1
    @Johnykutty alright, I'll implement that instead & update my question when I've done so, thank you :) Commented Mar 16, 2016 at 10:05
  • 1
    @Johnykutty I've edittd my question, something like that? Commented Mar 16, 2016 at 10:09
  • 1
    @Johnykutty the application:openURL:options didn't work either Commented Mar 16, 2016 at 10:43

1 Answer 1

6
var scheme: String!
var path: String!

var query: String!

func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {

  scheme = url.scheme
  path = url.path
  query = url.query

  return true
}

need to be in AppDelegate.Swift you can then access it in the viewcontroller by doing -

var appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate;

and you can then call a variable by doing -

var something = pathScheme.appDelegate;
Sign up to request clarification or add additional context in comments.

1 Comment

Nice work! Thanks! I was struggling with the same problem :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.