iOS 9 兼容版本的 NSTimer scheduledTimerWithTimeInterval :repeats:block:?

标签 ios objective-c

我在 iOS 10 中使用以下代码,但在 iOS 9 中运行时它崩溃了。我不认为NSTimer scheduledTimerWithTimeInterval:repeats:block:支持 iOS 9。如何实现可在 iOS 8 - 10 中运行的计时器?

static NSTimer* timer = nil;

- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }];
}

-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [timer invalidate];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

最佳答案

您似乎在使用 iOS10 中引入的功能。在您链接的页面的下方是 iOS 2 中的一个功能。

https://developer.apple.com/documentation/foundation/nstimer/1408356-timerwithtimeinterval?language=objc

改用它。

关于iOS 9 兼容版本的 NSTimer scheduledTimerWithTimeInterval :repeats:block:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45965895/

相关文章:

ios - 呈现新的 View Controller 。选项卡式图标消失

objective-c - UINavigationController 样式

iphone - CALayers 没有因 UIView 的边界变化而调整大小。为什么?

ios - 无法显示我的自定义 UITableViewCell

iphone - 如何检查 NSMutableArray 是否包含值(null)?

iphone - NSFetchRequest 不显示任何内容

ios - 如何使用uiviewcontroller实现滑出式菜单?

ios - 核心蓝牙 : CBPeripheral disconnects every ~10 seconds

ios - 在解析推送通知中将用户名作为变量发送

iphone - 如何在 iPhone 中访问应用程序包之外的文件