Update demo app to handle push message custom payload - Adobe-Marketing-Cloud/aml-summit-lab GitHub Wiki

Overview

In this section, we'll add some code to the app to handle the custom payload that comes in with the push message.

Implementation Steps

1.) Open AppDelegate.m 2.) Add the following code snippets:

2a) Extract the custom payload everytime we receive a push notification

// app target < iOS 7
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
	// only send the hit if the app is not active
	if (application.applicationState != UIApplicationStateActive) {
	/* Adobe Analytics
	*
	* 1. when the user opens your app by clicking through your push message, report it to the Adobe SDK
	*/
	[ADBMobile trackPushMessageClickThrough:userInfo];
        NSString *customColorString = [userInfo objectForKey:@"color"];
        
        if (customColorString != nil && customColorString.length > 0){
            NSDictionary *allColors = TEXT_COLOR_NAMES;
            UIColor *customColor = allColors[customColorString];
            [self customizeUsingPushData:customColor];
        }
    }
}
// app target >= iOS 7
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
	fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
	// only send the hit if the app is not active
	if (application.applicationState != UIApplicationStateActive) {
	/* Adobe Analytics
	*
	* 1. when the user opens your app by clicking through your push message, report it to the Adobe SDK
	*/
	[ADBMobile trackPushMessageClickThrough:userInfo];
        
        NSString *customColorString = [userInfo objectForKey:@"color"];
        if (customColorString != nil && customColorString.length > 0){
            NSDictionary *allColors = TEXT_COLOR_NAMES;
            UIColor *customColor = allColors[customColorString];
            [self customizeUsingPushData:customColor];
        }    
   }
   completionHandler(UIBackgroundFetchResultNoData);
}

2b) Here, customizeUsingPushData is a method that sets the text color of user profile data to the input color.

- (void)customizeUsingPushData:(UIColor *)customColor{
...
...
}

Next Steps

Configure custom payload in Push Message