我想每隔3分钟在后台进行一次调用,所以我使用Twilio来实现。我可以在前台为每3个人打一次电话,但当我在后台的iPhone设备上构建应用程序时,它不工作。一段时间后,fb会话将被注销。
UIApplication *app1 = [UIApplication sharedApplication];
//create new uiBackgroundTask
__block UIBackgroundTaskIdentifier bgTask1 = [app1 beginBackgroundTaskWithExpirationHandler:^{
[app1 endBackgroundTask:bgTask1];
bgTask1 = UIBackgroundTaskInvalid;
}];
//and create new timer with async call:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//run function methodRunAfterBackground
timerForPhone = [NSTimer scheduledTimerWithTimeInterval:[string integerValue] target:self selector:@selector(methodForMakingCall) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timerForPhone forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});发布于 2015-10-12 19:41:29
在你把应用程序放到后台后,你对它没有太多的控制。操作系统可以根据资源需求将其杀死。与Android不同的是,你需要唤醒你的应用程序才能执行一些逻辑操作。有一些解决方法,如使用位置管理器的显着变化机制,但仍然没有一个指定的API。当您在iOS上执行一些后台逻辑时,您需要牢记这一点。
https://stackoverflow.com/questions/33080069
复制相似问题