我正在检查我的应用程序与iOS 8的兼容性,我得到以下登录控制台“尝试标记应用程序图标,但尚未收到用户的许可,以标记应用程序”。有谁能帮我摆脱这个警告吗?是的,我的应用程序在应用程序图标和TabBar图标上显示徽章。
发布于 2014-10-06 20:23:06
下面是我在AppDelegate中做的事情
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// registering for remote notifications
[self registerForRemoteNotification];
return YES;
}
- (void)registerForRemoteNotification {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
}
#endif
发布于 2014-09-24 17:10:25
苹果为注册通知和处理徽章制作了新的API。
请参阅WWDC 2014会议视频:https://developer.apple.com/videos/wwdc/2014/?id=713、http://asciiwwdc.com/2014/sessions/713 (纯文字版)和https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/registerUserNotificationSettings
用户可以在设置中更改每个UIUserNotificationType (UIUserNotificationTypeBadge, UIUserNotificationTypeSound, UIUserNotificationTypeAlert)
的权限。
在更改徽章之前,您必须检查权限。
来自我的AppDelegate的代码示例:
- (BOOL)checkNotificationType:(UIUserNotificationType)type
{
UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
return (currentSettings.types & type);
}
- (void)setApplicationBadgeNumber:(NSInteger)badgeNumber
{
UIApplication *application = [UIApplication sharedApplication];
if(SYSTEM_VERSION_LESS_THAN(@"8.0")) {
application.applicationIconBadgeNumber = badgeNumber;
}
else {
if ([self checkNotificationType:UIUserNotificationTypeBadge]) {
NSLog(@"badge number changed to %d", badgeNumber);
application.applicationIconBadgeNumber = badgeNumber;
}
else {
NSLog(@"access denied for UIUserNotificationTypeBadge");
}
}
}
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
currentUserNotificationSettings方法在UI应用程序实例中可用,它将为您提供最新的用户通知首选项。
使用工卡编号:
[self setApplicationBadgeNumber:0];
而不是
application.applicationIconBadgeNumber = 0;
发布于 2014-09-23 20:55:14
您可以使用
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif
https://stackoverflow.com/questions/25973364
复制相似问题