{"__v":0,"_id":"58ab6fa66c036625009819a4","category":{"__v":14,"_id":"5540d91bbb9e762d00f594ad","pages":["5540d9835cf9682100d61acc","5540d9f25cf9682100d61acf","55a3c52253611017004386bd","55a7744495bf6d25009a0505","55a8f59ac8bd450d000dd11f","55a8f945c8bd450d000dd128","55a8fb52c8bd450d000dd131","55a9046fc8bd450d000dd152","55a9094827a17d210052522a","55a90b6bcf45e1390093f2b8","55a90dd5c8bd450d000dd167","55a911afc8bd450d000dd179","55a9120acf45e1390093f2d0","55ba2eadb3612925009d670a"],"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-29T13:14:03.694Z","from_sync":false,"order":3,"slug":"ios","title":"iOS"},"parentDoc":null,"project":"5540ce1b31827a0d007ab1cc","user":"5540e0f5bb9e762d00f594c0","version":{"__v":31,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-02-20T22:37:26.988Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"iOS 10.3 brings the ability to change iOS app icon. Let's combine this with push notifications!\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/579830a-ezgif.com-resize_1.gif\",\n        \"ezgif.com-resize (1).gif\",\n        200,\n        355,\n        \"#cd7238\"\n      ]\n    }\n  ]\n}\n[/block]\nLooks like magic? Let's implement this!\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"XCode setup\"\n}\n[/block]\nFirst of all you need to add new icon images to your project and to **Info.plist** file.\n\nLocate \"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.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e8d3ce6-Info_plist.jpg\",\n        \"Info_plist.jpg\",\n        1694,\n        574,\n        \"#e3e3e3\"\n      ]\n    }\n  ]\n}\n[/block]\nLet'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:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{\\n\\t\\n\\tdispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\\n\\n\\t\\tNSDictionary *data = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:userInfo];\\n\\t\\tNSString * icon = [data objectForKey::::at:::\\\"changeIcon\\\"];\\n\\t\\tif([icon isEqualToString:@\\\"nil\\\"])\\n\\t\\t\\ticon = nil;\\n\\t\\t\\n\\t\\tNSLog(@\\\"icon is: %@\\\", icon);\\n\\t\\t\\n\\t\\t[[UIApplication sharedApplication] setAlternateIconName:icon completionHandler:^(NSError * _Nullable error) {\\n\\t\\t\\tNSLog(@\\\"Set icon error = %@\\\", error.localizedDescription);\\n\\t\\t}];\\n\\t});\\n\\n  //the rest of the code\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nNow go to the control panel and let's test this! Set the push title:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7305b78-PW_send_push.jpg\",\n        \"PW_send_push.jpg\",\n        1734,\n        1084,\n        \"#f1f1f1\"\n      ]\n    }\n  ]\n}\n[/block]\nSet the custom data. In this case I'll use \"xmas_sale\" as icon (see Info.plist setup):\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/63e4d3e-PW_custom_data.jpg\",\n        \"PW_custom_data.jpg\",\n        1746,\n        1024,\n        \"#1e737c\"\n      ]\n    }\n  ]\n}\n[/block]\nDone!\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/26de4e3-ezgif.com-resize_1.gif\",\n        \"ezgif.com-resize (1).gif\",\n        200,\n        355,\n        \"#cd7238\"\n      ]\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"changing-icon-on-ios103-with-push-notifications","type":"basic","title":"Changing icon on iOS10.3 with push notifications"}

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! [block:image] { "images": [ { "image": [ "https://files.readme.io/579830a-ezgif.com-resize_1.gif", "ezgif.com-resize (1).gif", 200, 355, "#cd7238" ] } ] } [/block] Looks like magic? Let's implement this! [block:api-header] { "type": "basic", "title": "XCode setup" } [/block] 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. [block:image] { "images": [ { "image": [ "https://files.readme.io/e8d3ce6-Info_plist.jpg", "Info_plist.jpg", 1694, 574, "#e3e3e3" ] } ] } [/block] 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: [block:code] { "codes": [ { "code": "- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{\n\t\n\tdispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{\n\n\t\tNSDictionary *data = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:userInfo];\n\t\tNSString * icon = [data objectForKey:@\"changeIcon\"];\n\t\tif([icon isEqualToString:@\"nil\"])\n\t\t\ticon = nil;\n\t\t\n\t\tNSLog(@\"icon is: %@\", icon);\n\t\t\n\t\t[[UIApplication sharedApplication] setAlternateIconName:icon completionHandler:^(NSError * _Nullable error) {\n\t\t\tNSLog(@\"Set icon error = %@\", error.localizedDescription);\n\t\t}];\n\t});\n\n //the rest of the code", "language": "objectivec" } ] } [/block] Now go to the control panel and let's test this! Set the push title: [block:image] { "images": [ { "image": [ "https://files.readme.io/7305b78-PW_send_push.jpg", "PW_send_push.jpg", 1734, 1084, "#f1f1f1" ] } ] } [/block] Set the custom data. In this case I'll use "xmas_sale" as icon (see Info.plist setup): [block:image] { "images": [ { "image": [ "https://files.readme.io/63e4d3e-PW_custom_data.jpg", "PW_custom_data.jpg", 1746, 1024, "#1e737c" ] } ] } [/block] Done! [block:image] { "images": [ { "image": [ "https://files.readme.io/26de4e3-ezgif.com-resize_1.gif", "ezgif.com-resize (1).gif", 200, 355, "#cd7238" ] } ] } [/block]