iOS 推送通知不播放声音且不显示角标(Badge)警报 [在 Objective C 中]

标签 ios objective-c push-notification

我使用的是此处提供的演示说明: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/

主要代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |                                                               
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);


    UIUserNotificationSettings *mySettings =
    [UIUserNotificationSettings settingsForTypes:types categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

    return YES;
}

-(void)MessageBox:(NSString *)title message:(NSString *)messageText
{
   // OLD way of sending push notifications:

   // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self
   //                                       cancelButtonTitle:@"OK" otherButtonTitles: nil];
   // [alert show];


    UIAlertController* alert=   [UIAlertController
                                  alertControllerWithTitle:title
                                  message:messageText
                                 preferredStyle:UIAlertControllerStyleAlert];


    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {}];

    [alert addAction:defaultAction];
    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];

}

我收到通知,但没有声音和角标(Badge)更新。 有什么建议吗?

最佳答案

您是否在 JSON 负载中包含了角标(Badge)和声音参数?

示例

{"aps":{"alert":"Example notification title","badge":1,"sound":"default"}}

我读过 Apple Push Notification Payload Documents熟悉一下自己。

关于iOS 推送通知不播放声音且不显示角标(Badge)警报 [在 Objective C 中],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37838043/

相关文章:

ios - CGRect 放大动画在 Xcode 10 中不起作用?

iOS Swift Facebook SDK 4 获取用户个人资料图片输出 "Question Mark"

objective-c - 尝试创建和填充 NSMutableDictionary 时出现内存错误

ios - Xamarin iOS - 推送通知 - 区分已点击的推送通知已到达

push-notification - 一次向多个(超过 3 个)主题发送 Firebase 云消息(又名推送通知)

ios - 可以将编译后的 .m 文件下载到应用程序中吗?

ios - 向场景中添加一个随机的 SKSpriteNode

iphone - 如何解析 JSON 响应?

objective-c - 我无法在URL中发送带有阿拉伯字母的请求

android - 如何使用通知图标修复小米特定的 RemoteServiceException?