我在我的应用程序中为 APNS 使用 Urbanairship ,一切顺利,但当我的应用程序未运行时,应用程序角标(Badge)编号未显示,但是当应用程序处于事件状态并收到推送时,角标(Badge)编号显示在应用图标上方。
我的代码如下:
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
UAConfig *config = [UAConfig defaultConfig];
[UAirship takeOff:config];
// Request a custom set of notification types
[UAPush shared].notificationTypes = (UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeNewsstandContentAvailability);
return YES;
}
- (void)applicationUIApplication *)app didFailToRegisterForRemoteNotificationsWithErrorNSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"%@",str);
}
- (void)applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)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];
}
- (void)applicationDidBecomeActiveUIApplication *)application {
application.applicationIconBadgeNumber = 0;
}
编辑:我也试过 -
- (void)applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)userInfo {
NSInteger badgeNumber = [application applicationIconBadgeNumber];
[application setApplicationIconBadgeNumber:++badgeNumber];
}
但仍然没有运气,我做错了什么?
Best Answer-推荐答案 strong>
我遇到了同样的问题,来自 this question
如果您还注册了 UIRemoteNotificationTypeNewsstandContentAvailability ,则将其删除并重试。
关于ios - 当我的应用程序未激活时,PushNotification 角标(Badge)编号未显示?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/22601649/
|