I would call a NSURLSessionDataTask in appDelegate when the app is open from mail, so in this function
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
I tried but doesn't work, why??
I need to get a query from this function
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSURLComponents *components = [[NSURLComponents alloc] init];
components.query = [url query];
BOOL confirmRegistration = NO;
NSString *userToken;
for (NSURLQueryItem *queryItem in components.queryItems) {
if ([queryItem.name isEqualToString:@"userToken"])
{
userToken = queryItem.value;
}
else if ([queryItem.name isEqualToString:@"registrationType"])
{
if ([queryItem.value isEqualToString:@"confirmRegistration"])
{
confirmRegistration = YES;
}
}
}
//la app è stata aperta con la mail di conferma registrazione
if (confirmRegistration)
{
NSDictionary* userInfo = @{@"userToken": userToken};
[[NSNotificationCenter defaultCenter] postNotificationName:@"confirmRegistration" object:nil userInfo:userInfo];
}
return YES;
}
Thank you
When Application is opened from anywhere, the application:didFinishLaunchingWithOptions:
is called.
There you check the launchingOptions to see what triggered the opening for application.
For instance, if application is opened using push notifications. You do something like below.
if let userInfo = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
self.application(application, didReceiveRemoteNotification: userInfo)
}
You can check the keys which you get when you open the application from Mail.
UPDATE
There are keys like UIApplicationLaunchOptionsSourceApplicationKey
and UIApplicationLaunchOptionsURLKey
which you can print or compare to what triggered the application launch and then start your work.
When you open your application from Mail then print the following and use it to compare and start your work.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
print(launchOptions?[UIApplicationLaunchOptionsSourceApplicationKey])
print(launchOptions?[UIApplicationLaunchOptionsURLKey])
return true
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments