2016-11-10 82 views
3

我后移动到10.12/Sierra和Xcode的8.1撞我的头靠在一个奇数错误:琐碎 “+ [的NSTimer scheduledTimerWithTimeInterval:重复:块:]:无法识别选择” 错误

+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: 
    unrecognized selector sent to class 0x7fff78f1fa88 

最最小代码(创建一个新项目的默认设置)重现此:

// AppDelegate.m 
// 

#import "AppDelegate.h" 

@interface AppDelegate() 

@property (weak) IBOutlet NSWindow *window; 
@property (strong, nonatomic) NSTimer * timer; 
@end 

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 
    self.timer = [NSTimer scheduledTimerWithTimeInterval:10 
          repeats:YES 
          block:^(NSTimer * _Nonnull timer) 
    { 
     NSLog(@"Ping from %@", timer); 
    }]; 
} 

链接包括(核心)基础类和'all_load'。必须是完全微不足道的东西 - 但不能达到目的。

任何和所有的帮助表示赞赏。

谢谢,

Dw。

+0

不管它的价值,这些代码不会崩溃,我(10.12.1时,Xcode 8.1)。 –

回答

24

+ [NSTimer scheduledTimerWithTimeInterval:repeats:block:]是一个iOS 10.0+方法。你可能试图在iOS 9.x上运行它?

https://developer.apple.com/reference/foundation/nstimer/2091889-scheduledtimerwithtimeinterval?language=objc

+1

您可以使用以下代码检查新方法是否存在,并在需要时回退到较旧的API。如果([[NSTimer类] respondsToSelector:@selector(scheduledTimerWithTimeInterval:repeatats:block :)]){ } – Awesomeness

+0

宾果,它是正确的 –

+0

我想知道为什么我只在9.x设备上面对这种奇怪的崩溃。谢谢亚历山德罗 https://developer.apple.com/documentation/foundation/nstimer/2091888-timerwithtimeinterval?language=objc 如果([self.timer respondsToSelector:@selector ]){ // Code for iOS 10.0+ } else { // IOS版本低于10.0的代码 } – Jitendra

相关问题