gcdasyncsocket后台文件传输 [英] gcdasyncsocket background file transfer

查看:437
本文介绍了gcdasyncsocket后台文件传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个设备需要在后台或LockScreen中继续传输数据。

Having two devices that need to keep transferring data while in background or in LockScreen.

有关后台的主要资源位于 https://developer.apple.com/library/ios/documentation/iPhone/Conceptual /iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

The main resource about backgrounding is available on https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

到目前为止,我期待了解如何实现这样的上述行为:在场景其中正在进行传输,其中一个应用程序(或两者)进入后台。显然,我们已经完成了可恢复的转移管理工作。

So far I'm looking forward to understand how is it expected to implement such above mentioned behaviour: in a scenario where a transfer is in progress and one of the apps (or both) goes into background. Obviously we have resumable transfer management working already.

我已经收集存根和答案,结果如下:

I've been collecting stubs and answers about and I've ended up with the following:


  1. 确保每个套接字都是可背景的。

  1. Ensure every socket is backgroundable.

[socket performBlock:^{
         [socket enableBackgroundingOnSocket];
     }];


  • 为了保持背景,即使在锁定屏幕,我读了一个答案,类似于didFinishLaunchingWithOptions的末尾,但在[self backgroundHandler]方法中有什么代码?

  • To keep backgrounding even when in Lock Screen, I read an answer saying that we should have something like at the end of didFinishLaunchingWithOptions but what code is in [self backgroundHandler] method?

    BOOL backgroundAccepted = [[UIApplication sharedApplication]
    setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];
    if (backgroundAccepted)
        NSLog(@"background handler accepted");
    
    return YES;
    


  • UIApplication的applicationDidEnterBackground委托方法显示

  • The applicationDidEnterBackground delegate method of UIApplication shows

    - (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), ^{
    
    });
    



  • 推荐答案

    我得到它的工作下面的教程,但看起来像GCDAsyncSocket不再维护,所以它只能在iOS7上工作。

    I got it working following this tutorial but looks like GCDAsyncSocket is no longer maintained so it will work only on iOS7.

    http://www.objc.io/issue-5/multitasking.html

    在iOS 8下执行背景文件传输我正在使用AFNetworking库( http://afnetworking.com

    To do background file transfer under iOS 8 I am using AFNetworking library (http://afnetworking.com)

    这篇关于gcdasyncsocket后台文件传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆