我正在尝试将固件文件从我的应用程序传输到可穿戴硬件。 这需要一些时间,当我的应用程序进入后台或按下锁定按钮时,固件传输过程将停止。
理想情况下,它应该继续传输固件。我正在使用此方法在后台继续该过程,并且还声明了对后台模式的支持。
- (void)applicationDidEnterBackground:(UIApplication *)application {
bgTask = 0;
bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
//[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
//[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
此方法无法完成任务。
但是如果我在Appdelegate中使用这个方法 - didFinishLaunchingWithOptions就行了。
但是将这段代码放在上面的方法中有一个权衡,即如果我没有传输固件并且应用程序进入后台,那么在3分钟之后这段代码将删除应用程序和蓝牙连接中断。< / p>
如果我根本不使用此方法,则连接将保持不变,直到手动中断,但不会发生后台传输。
我必须同时保持两个操作。请提出一些关于这个特殊问题的建议。
提前致谢。
答案 0 :(得分:0)
尝试使用BackgroundModes
运行您的应用程序
并从didEnterInbackground