I want in my iOS application to start a timer when the app is running in the background and when the app is closed. The timer must check every 30 minutes of there a new noti
Write this both methos in your Appdelegate.m file
//For Objective c
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self TimerMethod];
}
-(void)TimerMethod
{
//Every 30 minute call the functions
_timer=[NSTimer scheduledTimerWithTimeInterval:1800.0f target:self selector:@selector(updateMethod:) userInfo:nil repeats:YES];
}
- (void)updateMethod:(NSTimer *)theTimer
{
NSLog(@"Timer set now");
}
//For Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool
{
self.TimerMethod()
}
func TimerMethod()
{
var timer = NSTimer.scheduledTimerWithTimeInterval(1800, target: self, selector: "updateMethod", userInfo: nil, repeats: true)
}
func updateMethod()
{
print("set timer now")
}