NSURLSessionDataTask in appdelegate

Vincenzo Putignano

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

Rahul Katariya

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Chain request using NSURLSessionDataTask

From Dev

NSURLSessionDataTask acting suspiciously slow

From Dev

How to use NSURLSessionDataTask in Swift

From Dev

GCD to wait for NSURLSessionDataTask to complete

From Dev

NSURLSessionDataTask in background session

From Dev

NSURLSessionDataTask: Application crashes in NSOperationQueue

From Dev

GCD to wait for NSURLSessionDataTask to complete

From Dev

Force wait for NSURLSessionDataTask completion

From Dev

When to use NSURLSessionDownloadTask and NSURLSessionDataTask?

From Dev

Wait for NSURLSessionDataTask to come back

From Dev

Error with NSURLSessionDataTask in iOS 10

From Dev

Showing the file download progress with NSURLSessionDataTask

From Dev

How to get NSDictionary from NSURLSessionDataTask

From Dev

NSURLSessionDataTask not executing the completion handler block

From Dev

NSURLSessionDataTask timeout subsequent requests failing

From Dev

Non-unique NSURLSessionDataTask taskIdentifiers

From Dev

Xcode loop array of URLs with NSURLSessionDataTask

From Dev

How to execute multiple NSURLSessionDataTask serially?

From Dev

Does NSURLSessionDataTask get paused on background?

From Dev

AppDelegate NIDAction

From Dev

AppDelegate NIDAction

From Dev

How to get status code from NSURLSessionDataTask?

From Dev

What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

From Dev

NSURLSessionDataTask dataTaskWithURL completion handler not getting called

From Dev

Converting NSURLSessionDataTask into a Download task with Background support

From Dev

How to get data to return from NSURLSessionDataTask

From Dev

NSURLSessionDataTask fails on simple HTTPS URL with error -1002

From Dev

iOS7 Background Synchronization (with NSURLSessionDataTask?)

From Dev

How to get data to return from NSURLSessionDataTask in Swift

Related Related

  1. 1

    Chain request using NSURLSessionDataTask

  2. 2

    NSURLSessionDataTask acting suspiciously slow

  3. 3

    How to use NSURLSessionDataTask in Swift

  4. 4

    GCD to wait for NSURLSessionDataTask to complete

  5. 5

    NSURLSessionDataTask in background session

  6. 6

    NSURLSessionDataTask: Application crashes in NSOperationQueue

  7. 7

    GCD to wait for NSURLSessionDataTask to complete

  8. 8

    Force wait for NSURLSessionDataTask completion

  9. 9

    When to use NSURLSessionDownloadTask and NSURLSessionDataTask?

  10. 10

    Wait for NSURLSessionDataTask to come back

  11. 11

    Error with NSURLSessionDataTask in iOS 10

  12. 12

    Showing the file download progress with NSURLSessionDataTask

  13. 13

    How to get NSDictionary from NSURLSessionDataTask

  14. 14

    NSURLSessionDataTask not executing the completion handler block

  15. 15

    NSURLSessionDataTask timeout subsequent requests failing

  16. 16

    Non-unique NSURLSessionDataTask taskIdentifiers

  17. 17

    Xcode loop array of URLs with NSURLSessionDataTask

  18. 18

    How to execute multiple NSURLSessionDataTask serially?

  19. 19

    Does NSURLSessionDataTask get paused on background?

  20. 20

    AppDelegate NIDAction

  21. 21

    AppDelegate NIDAction

  22. 22

    How to get status code from NSURLSessionDataTask?

  23. 23

    What is difference between NSURLSessionDataTask vs NSURLSessionDownloadTask

  24. 24

    NSURLSessionDataTask dataTaskWithURL completion handler not getting called

  25. 25

    Converting NSURLSessionDataTask into a Download task with Background support

  26. 26

    How to get data to return from NSURLSessionDataTask

  27. 27

    NSURLSessionDataTask fails on simple HTTPS URL with error -1002

  28. 28

    iOS7 Background Synchronization (with NSURLSessionDataTask?)

  29. 29

    How to get data to return from NSURLSessionDataTask in Swift

HotTag

Archive