Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handleOpenURL won't trigger iOS Swift 2

I am trying to get an Instagram authentication token for an app Im working on, I have the app opening safari, Im able to log in and then it send me back to the app, but when it transfers me back to the app, handleOpenURL is not triggering in AppDelegate. Here is a sample of my code:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

....
    func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool {
        InstagramAPIManager.sharedInstance.processOAuthStep1Response(url)
        print(url)
        print("handleOpenURL")
        return true
    }

}

and here is a my API Manager code that is triggering safari to open:

import Foundation
import Alamofire

class InstagramAPIManager {
    static let sharedInstance = InstagramAPIManager()

    func startOAuth2Login() {
        let clientID: String = "abcdefg"
        let authPath:String = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=grokInstagram://?aParam=paramVal&response_type=code"
        if let authURL:NSURL = NSURL(string: authPath)
        {
            UIApplication.sharedApplication().openURL(authURL)
        }
    }
....

}

Any help would be appreciated!

like image 877
Trevomatic Avatar asked Dec 13 '25 02:12

Trevomatic


1 Answers

In iOS 9, application:handleOpenURL: is deprecated. Instead, you should be using:

func application(app: UIApplication, 
    openURL url: NSURL, options: [String : AnyObject]) -> Bool {
like image 176
matt Avatar answered Dec 14 '25 15:12

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!