To do this first, you need to go to your Info.Plist file and add some properties to the Icon-File, which
<key>CFBundleIcons</key> <dict> <key>CFBundleAlternateIcon</key> <dict> <key>first_icon</key> <dict> <key>CFBundleIconFile</key> <array> <string>first_icon.png</string> </array> </dict> <key>second_icon</key> <dict> <key>CFBundleIconFile</key> <array> <string>second_icon.png</string> </array> </dict> </dict> <key>CFBundlePrimaryIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string></string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> <key>UINewsstandIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string></string> </array> <key>UINewsstandBindingType</key> <string>UINewsstandBindingTypeMagazine</string> <key>UINewsstandBindingEdge</key> <string>UINewsstandBindingEdgeLeft</string> </dict> </dict>
Now you need to configure the settings in the AppDelegate file
- (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 *notificationData = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:userInfo]; NSString * notiIcon = [notificationData objectForKey:@"newIcon"]; if([notiIcon isEqualToString:@"nil"]) notiIcon = nil; NSLog(@"icon is: %@", notiIcon); [[UIApplication sharedApplication] setAlternateIconName:notiIcon completionHandler:^(NSError * _Nullable error) { NSLog(@"Set icon error = %@", error.localizedDescription); }]; });
now from any dashboard you send a notification to the goto application, and there will be an option called Action or something like send Custom data will send a key-value pair to the code, we use the 'newIcon' key, so send it like this
{"newIcon":"first_icon"}
now when you send a notification with the name of the icon that will appear.
This will work.
cpt. Sparrow
source share