OStack程序员社区-中国程序员成长平台

标题: ios - 对部署目标 8.1 和 XCODE 6.1 使用远程通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:29
标题: ios - 对部署目标 8.1 和 XCODE 6.1 使用远程通知

我想对部署目标 8.1 和 xcode 6.1 使用远程通知
我正在使用以下代码

if ([application respondsToSelectorselector(registerUserNotificationSettings]) {
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

但它在其他部分向我展示了 deprecated 方法......所以现在我该如何摆脱它...... 我尝试的其他代码是:

enter image description here



Best Answer-推荐答案


您可以像这样忽略不推荐使用的警告:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
    if ([application respondsToSelectorselector(registerUserNotificationSettings]) {
        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#pragma clang diagnostic pop

    }
#else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif

this post :

关于ios - 对部署目标 8.1 和 XCODE 6.1 使用远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28980696/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4