It is a bug in Aerogear with iOS 9.3 can not get UIApplicationLaunchOptionsURLKey when using openurl instead of launch option delegate (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions { } Here what we get from openurl delegate In - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options { NSLog(@"options:%@",options); NSLog(@"launch url: %@", url);
return YES; }
//This is what we get from options options:{ UIApplicationOpenURLOptionsOpenInPlaceKey = 0; UIApplicationOpenURLOptionsSourceApplicationKey = "com.indegene.FieldCentral"; }
And this from url launch url: fcapp:/?code=HypbUShRTFFgCTrJW3Ukrum1MQmksNsF6jr7Z_waw1w.584754af-54d6-418e-b019-fc8bb6df3837
I could not find UIApplicationLaunchOptionsURLKey neither in options nor in url from above delegate. Aerogear sdk is not able to extract code from url as it was checking UIApplicationLaunchOptionsURLKey in extractCode function below func extractCode(notification: NSNotification, completionHandler: (AnyObject?, NSError?) -> Void)
When I changed this function a bit I am able to get token and claim Id details. func extractCode(notification: NSNotification, completionHandler: (AnyObject?, NSError?) -> Void) { let url: NSURL? = (notification.userInfo as! [String: AnyObject])[UIApplicationLaunchOptionsURLKey] as? NSURL
let mydic = notification.userInfo // extract the code from the URL let code = mydic!["code"] //self.parametersFromQueryString(url?.query)["code"] // if exists perform the exchange if (code != nil) { self.exchangeAuthorizationCodeForAccessToken(code as! String, completionHandler: completionHandler) // update state state = .AuthorizationStateApproved } else {
let error = NSError(domain:AGAuthzErrorDomain, code:0, userInfo:["NSLocalizedDescriptionKey": "User cancelled authorization."]) completionHandler(nil, error) } // finally, unregister self.stopObserving() }
// this is how I am doing a post notification [[NSNotificationCenter defaultCenter] postNotificationName:@"AGAppLaunchedWithURLNotification" object:nil userInfo:self.launchParams];
where self.launchParams is a dic extracted from url launch url: fcapp:/?code=HypbUShRTFFgCTrJW3Ukrum1MQmksNsF6jr7Z_waw1w.584754af-54d6-418e-b019-fc8bb6df3837
// This is how self.launchParams looks like self.launchParams:{ code = "HypbUShRTFFgCTrJW3Ukrum1MQmksNsF6jr7Z_waw1w.584754af-54d6-418e-b019-fc8bb6df3837"; }
I think you should extract the code from url instead of using UIApplicationLaunchOptionsURLKey
|