【问题标题】:When I change my project deployment target from iOS 8.4 to iOS 9.0 I receive a lot of error messages当我将项目部署目标从 iOS 8.4 更改为 iOS 9.0 时,我收到很多错误消息
【发布时间】:2015-09-17 01:34:08
【问题描述】:

当我将项目部署目标从 iOS 8.4 更改为 iOS 9.0 时,我收到很多错误消息,例如:

'initWithRequest:delegate:startImmediately:' 已弃用:在 iOS 9.0 中首次弃用 - 使用 NSURLSession(参见 NSURLSession.h)

- (void)operationDidStart {
[self.lock lock];
if (![self isCancelled]) {
    self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO];

    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    for (NSString *runLoopMode in self.runLoopModes) {
        [self.connection scheduleInRunLoop:runLoop forMode:runLoopMode];
        [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
    }

    [self.outputStream open];
    [self.connection start];
}
[self.lock unlock];

dispatch_async(dispatch_get_main_queue(), ^{
    [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingOperationDidStartNotification object:self];
});
}

'UIAlertView' 已弃用:首先在 iOS 9.0 中弃用 - UIAlertView 已弃用。改用 UIAlertController 和 UIAlertControllerStyleAlert 的preferredStyle

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil, nil];

'init' 已弃用:首先在 iOS 9.0 中弃用 - 改用 -initWithConcurrencyType:

_managedObjectContext = [[NSManagedObjectContext alloc] init];

'initWithRequest:delegate:' 已弃用:首先在 iOS 9.0 中弃用 - 使用 NSURLSession(参见 NSURLSession.h)

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

对于任何这些错误的任何帮助将不胜感激。

【问题讨论】:

  • 这些不是错误消息,而是警告。您需要查看 iOS9 的文档,该文档将明确告诉您已弃用的方法和类的替代方案是什么。您现在无需执行任何操作,但一段时间后这些已弃用的项目将从 SDK 中删除,因此您最终需要将它们迁移到替代品。
  • 当您将部署目标设置为 iOS 9 时,这意味着您的应用将仅支持 iOS 9 及以上版本,不支持以下版本。保持原样并在 iOS 9 设备上测试您的应用是否存在兼容性问题。
  • 补充@Rog 所说的内容 - 查找部署目标和基础 SDK 之间的区别。另请阅读 iOS 文档中的“SDK 兼容性指南”。
  • 是的。大多数人升级到 iOS 9 需要几个月的时间。但总会有那些不升级或无法升级的,因此支持 iOS 8 应该至少支持一年,如果不是更长的话(取决于你的应用程序和你的观众)。
  • 是的,没错。

标签: ios objective-c ios9 deprecation-warning


【解决方案1】:

在 iOS 9 中,您使用 UIAlertViewController 而不是 UIAlertView

UIAlertController *alertView= [UIAlertController
                                      alertControllerWithTitle:title
                                      message:message
                                      preferredStyle:UIAlertControllerStyleAlert];
[alertView addAction: [UIAlertAction actionWithTitle:otherButtonTitle
               style:UIAlertActionStyleDefault
               handler:^(UIAlertAction * action)
               {

               }]];
[self presentViewController:alertView animated:YES completion:nil];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 2013-01-24
    相关资源
    最近更新 更多