[英]Icon for push notification?
I am working on a chat app that receive push notification. 我正在开发一个接收推送通知的聊天应用。 I want to provide images/icon that will be used by iOS to display in push notification , where can I specify that in Xcode?
我想提供iOS将用于在推送通知中显示的图像/图标,在哪里可以在Xcode中指定?
To Accomplish this firstly you need to goto your Info.Plist file and add some properties in Icon-File that is 要首先完成此任务,您需要转到Info.Plist文件并在Icon-File中添加一些属性
<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 settings in your AppDelegate
file 现在,您需要在
AppDelegate
文件中配置设置
- (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 the notification to the app goto that and there would be and option named Action
or something like send Custom data
send a key-value
pair in code we are using key 'newIcon' so send it like that 现在从任何仪表板你发送通知到应用程序goto那将有和选项名为
Action
或类似send Custom data
发送代码中key-value
对我们使用键'newIcon'所以发送它就像那样
{"newIcon":"first_icon"}
now when you'll send the notification with iconName that will appear. 现在,当您发送带有将出现的iconName的通知时。
This will Work.. 这将工作..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.