在AppDelegate
我定义了
AppDelegate.h
@property (strong, nonatomic) NSTimer *notificationTimer;
AppDelegate.m
@synthesize notificationTimer = _notificationTimer;
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"applicationDidBecomeActive");
self.notificationTimer = [NSTimer timerWithTimeInterval:5
target:self
selector:@selector(checkForNotifications:)
userInfo:nil
repeats:YES];
[self.notificationTimer fire];
}
checkForNotifications:
达到一次但从不重复。为什么呢?
答案 0 :(得分:2)
使用:
self.notificationTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(checkForNotifications) userInfo:nil repeats:YES];