gpt4 book ai didi

iphone - 推送通知徽章不来

转载 作者:太空狗 更新时间:2023-10-30 03:42:23 26 4
gpt4 key购买 nike

我正在将此代码用于苹果推送通知,推送通知即将到来,但它们没有任何徽章,任何建议此代码有什么问题,我没有收到徽章。我已经检查了设置选项卡,那里有徽章。

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

[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

}

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken1 {

NSString *str = [NSString
stringWithFormat:@"%@",deviceToken1];
NSLog(@"%@",str);

self.deviceToken = [NSString stringWithFormat:@"%@",str];
NSLog(@"dev --- %@",self.deviceToken);
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@"<" withString:@""];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@" " withString:@""];
self.deviceToken = [self.deviceToken stringByReplacingOccurrencesOfString:@">" withString:@""];
NSLog(@"dev --- %@",self.deviceToken);


}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"%@",str);

}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received notification: %@", userInfo);
//[self addMessageFromRemoteNotification:userInfo];

NSString* alertValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
NSLog(@"my message-- %@",alertValue);
int badgeValue= [alertValue intValue];

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];


}

最佳答案

我的服务器端编码存在问题,因为我刚刚发现徽章值必须隐式设置为整数才能获得所需的结果。

因为我在徽章值中得到空值。

关于iphone - 推送通知徽章不来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9734451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com