有两台设备需要在后台或LockScreen中继续传输数据。
上找到到目前为止,我期待了解如何实现上述行为:在传输正在进行且其中一个应用程序(或两者)进入后台的情况下。显然我们已经有可恢复的转移管理工作了。
我一直在收集存根和答案,我最终得到了以下内容:
确保每个套接字都可以查看。
[socket performBlock:^{
[socket enableBackgroundingOnSocket];
}];
为了在Lock Screen中保持背景,我读了一个答案,说我们应该有类似于didFinishLaunchingWithOptions的结尾但是[self backgroundHandler]方法中的代码是什么?
BOOL backgroundAccepted = [[UIApplication sharedApplication]
setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];
if (backgroundAccepted)
NSLog(@"background handler accepted");
return YES;
UIApplication的applicationDidEnterBackground委托方法显示
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"=== DID ENTER BACKGROUND ===");
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
NSLog(@"Multitasking Supported");
else
return;
// Shall I remove my KVO observers when in background?? I guess NOT, right? :D
//[[NSNotificationCenter defaultCenter] removeObserver:self];
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"End of tolerate time. Application should be suspended now if we do not ask more 'tolerance'");
// [self askToRunMoreBackgroundTask]; This code seems to be unnecessary. I'll verify it.
}];
if (bgTask == UIBackgroundTaskInvalid)
NSLog(@"This application does not support background mode");
else
NSLog(@"Application will continue to run in background");
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
});
答案 0 :(得分:0)
我按照本教程开始工作,但看起来不再维护GCDAsyncSocket,因此它只适用于iOS7。
http://www.objc.io/issue-5/multitasking.html
在iOS 8下进行后台文件传输我正在使用AFNetworking库(http://afnetworking.com)