Custom key Handling in Swift 2.3

Hello sir, 

I am working on a E - commerce app for iOS in swift 2.3, I want to know that how to handle the custom key data in Xcode (swift 2.3) of a notification, as there is no proper documentation for custom key data handling in UAirShip SDK.  i.e. If we get { "Product_id": 123 } as custom key and want to decide the flow of application according to this key.

Didn't find what you were looking for?

New post

Comments

1 comment

  • Hi Tyson,

    Typically handling the custom key data within the notification will need to done when the app is foregrounded or the push is tapped on.

    To do so, you're going to have customize the Push Delegate.

    Doing so will allow you to handle the notification as it comes in. Once you have access to the notification dictionary, you'll then be able to access the keys and values within the dictionary to be able to perform the action you need to do.

    So, as an example, you might have something like:

    - (void)launchedFromNotification:(NSDictionary *)notification fetchCompletionHandler:(void ( ^ ) ( UIBackgroundFetchResult result ))completionHandler{
        completionHandler(UIBackgroundFetchResultNoData);
        if (notification !=nil && [notification objectForKey:@"TEST_URL"] !=[NSNullnull] && [[notification objectForKey:@"TEST_URL"length] > 0 ) {
            NSString *urlLink=[NSString stringWithFormat:@"%@",[notificationobjectForKey:@"TEST_URL"]];
            NSURL *url = [NSURL URLWithString:urlLink];
            if (![[UIApplication sharedApplicationopenURL:url]) {
                NSLog(@"Failed to open url:%@",[url description]);
            }
        } 
    }
    To help with figuring out the format, I would definitely recommend taking a look at the Swift sample app that is included with the library. There will be a PushHandler class that allows you to see how to modify the handler to customize the behavior to suit your needs.
    0

Please sign in to leave a comment.