【发布时间】:2023-03-11 04:04:01
【问题描述】:
我有一个应用程序,我想以新的 iOS 8.1 为目标,但我也希望拥有 iOS 7 的用户能够使用我的应用程序。因此,例如对于我的推送通知,在我的应用程序委托中我有
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
要为 iOS 8 和 iOS 7 打开推送通知,但是当我更改我的部署目标时,我收到警告说这已被弃用:
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
处理此问题的最佳方法是什么?对于提交到应用商店以及个人而言,我不希望在我的代码中看到警告。
提前感谢您的帮助。
编辑
这是一张警告图片,我看到我的部署目标是 iOS8.1,但不确定在哪里可以找到我的基础 SDK?这是图片:
【问题讨论】:
-
有时你只需要接受在为旧版本的 iOS 构建时会有弃用警告。只要它们仅在生产构建期间发生,您就可以在每次构建时检查列表以确保没有出现任何新内容。
-
请说明您的基础 SDK 和部署目标的设置。它应该分别是“最新(8.1)”和“iOS 7.0”。如果是这样,您只会收到自 iOS 7.0 起已弃用的方法的弃用警告。在这种情况下,只能使用 iOS 7.0 或更高版本的方法。
-
换句话说,如果您收到关于
registerForRemoteNotificationTypes的弃用警告,那么您的部署目标未设置为 iOS 7,而是设置为 iOS 8。 -
@rmaddy 我应该在“项目”下或“目标”下或两者下设置部署目标?
-
目标设置优先于项目设置。
标签: ios ios7 ios8 deprecated