我正在判断我的应用程序与iOS 8的兼容性,我在控制台"Attempting to badge the application icon but haven't received permission from the user to badge the application"中获得以下登录信息.谁能帮我摆脱这个警告吗.是的,我的应用程序在应用程序图标和TabBar图标上显示徽章.

推荐答案

以下是我在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

Objective-c相关问答推荐

如何从 C 方法调用 Objective-C 方法?

如何创建圆形按钮?

从 C# 到 Objective C 会有多大的飞跃

self.ivar 和 ivar 之间的区别?

防止同时多个按钮

判断正在使用的应用程序版本

判断是否显示 UIAlertView

在 Objective-C 中在 iPhone 上使用 HTTP POST 和 GET 的教程

为什么我的 UIButton 的内部修饰事件没有被调用?

lldb 无法打印变量值并显示错误:对 'id' 的引用不明确

Grand Central Dispatch (GCD) 与 performSelector - 需要更好的解释

如何删除应用程序可访问的所有 keys 串项目?

在 Objective-C 中,你在哪里声明一个常量?

主队列上的 dispatch_sync 与 dispatch_async

如何在 NSSet 或 NSArray 中搜索具有特定属性的特定值的对象?

如何在嵌入 UIViewController 的 UITableView 中直观地创建和使用静态单元格

-[MyClassName copyWithZone:] 无法识别的 Select 器发送到实例

Xcode 7 警告:目标文件是为比链接更新的 iOS 版本构建的

UICollectionView 断言失败

如何将 UITableView 滚动到特定位置