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

Gerwin
  • 1,572
  • 5
  • 23
  • 51
  • 2
    this method is deprecated try to use - application:openURL:options: – Johnykutty Mar 16 '16 at 09: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: http://www.mikesknowledgebase.com/pages/XCode/CustomURLs.htm – Mike Gledhill Mar 16 '16 at 10:04
  • 1
    @Johnykutty alright, I'll implement that instead & update my question when I've done so, thank you :) – Gerwin Mar 16 '16 at 10:05
  • 1
    @Johnykutty I've edittd my question, something like that? – Gerwin Mar 16 '16 at 10:09
  • 1
    @Johnykutty the application:openURL:options didn't work either – Gerwin Mar 16 '16 at 10:43

1 Answers1

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;
Gerwin
  • 1,572
  • 5
  • 23
  • 51