0

I need to execute one method at a intervals of 1min for every 30min. After 30mins, i want to sleep app for next 30mins.

I tried with UIBackgroundTaskIdentifier API, it allow me to execute code only for 180sec not more than that.

I dont want to use silent remote notifications.

Using NSTimer and NSRunLoop i have achieved this , but i wonder will apple reject my app when i submit.

please help me guys.

- (void)applicationDidEnterBackground:(UIApplication *)application {
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
    NSTimer *loop = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(insideLoop) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:loop forMode:NSRunLoopCommonModes];
}
-(void)insideLoop {
    NSLog(@"insideLoop");
}
sanjayzed
  • 57
  • 9

2 Answers2

0

Yes, Apple will reject your app if you do this.

I, too, have figured out a way to make an app stay awake in the background indefinitely, but it breaks Apple's rules and chews through the user's battery.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • yea that is my concern. so what do you suggest. thanks – sanjayzed Feb 23 '16 at 14:35
  • My suggest is: Don't do that. – Duncan C Feb 23 '16 at 15:46
  • Apple does not want apps that run indefinitely in the background, and will not allow them on the app store. You could distribute such an app to other employees using an enterprise account, or you could do such a thing on a Jailbroken phone, but aside from that, no. I don't think there is an app-store-approved way to do what you want to do. – Duncan C Feb 23 '16 at 17:40
  • what if i use silent remote notification as a way to bring app to background and execute piece of code using automated script in server side to send push messages every 1 min. – sanjayzed Feb 24 '16 at 05:05
  • waiting for your reply. – sanjayzed Feb 29 '16 at 16:48
  • Yes, you could probably do that, but Apple might reject your app when you submit it. I don't claim to be an expert on Apple's app store submission policies. – Duncan C Feb 29 '16 at 17:03
0

So there is no chance you will get a way with this particular approach.

There are options for triggering code when specific events happen to the device such as location change. The available options for background activity can be read here, but as I say what you have here won't get through.

user3192649
  • 313
  • 1
  • 4
  • 13