Changing icon on iOS10.3 with push notifications

iOS 10.3 brings the ability to change iOS app icon. Let's combine this with push notifications!

Looks like magic? Let's implement this!

XCode setup

First of all you need to add new icon images to your project and to Info.plist file.

Locate "CFBundleIcons" (a.k.a. "Icon files (iOS 5)) in your Info.plist file and add "CFBundleAlternateIcons" property there. See the full set-up on the screenshot below.

Let's add some code to push notifications handler didReceiveRemoteNotification function to change the app's icon. In this example we will use "changeIcon" custom data parameter to set the icon:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
	dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

		NSDictionary *data = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:userInfo];
		NSString * icon = [data objectForKey:@"changeIcon"];
		if([icon isEqualToString:@"nil"])
			icon = nil;
		NSLog(@"icon is: %@", icon);
		[[UIApplication sharedApplication] setAlternateIconName:icon completionHandler:^(NSError * _Nullable error) {
			NSLog(@"Set icon error = %@", error.localizedDescription);

  //the rest of the code

Sending a push to trigger icon change

Now go to the control panel and let's test this! Set the push title:

Set the custom data. In this case I'll use "xmas_sale" as icon (see Info.plist setup):


Changing icon on iOS10.3 with push notifications