Aas*_*gar 7 xcode push-notification ios
我正在开发一个接收推送通知的聊天应用.我想提供iOS将用于在推送通知中显示的图像/图标,在哪里可以在Xcode中指定?
小智 0
要完成此任务,首先您需要转到 Info.Plist 文件并在图标文件中添加一些属性,即
<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>
Run Code Online (Sandbox Code Playgroud)
现在您需要在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);
}];
});
Run Code Online (Sandbox Code Playgroud)
现在,从任何仪表板,您将通知发送到应用程序,然后转到该应用程序,并且会有名为的选项Action或类似在代码中send Custom data发送一key-value对的内容,我们正在使用密钥“newIcon”,因此像这样发送
{"newIcon":"first_icon"}
Run Code Online (Sandbox Code Playgroud)
现在,当您发送带有 iconName 的通知时,将会出现。
这会起作用..
| 归档时间: |
|
| 查看次数: |
2323 次 |
| 最近记录: |