ReactiveCocoa 异步压缩等处理

前端之家收集整理的这篇文章主要介绍了ReactiveCocoa 异步压缩等处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

代码

- (void) uploadScene:(NSString*)path{
    RACSignal *sg;
    WS(ws);
    sg = [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        dispatch_async(dispatch_get_global_queue(0,0),^(void){
            [ws zipPath:path];
            [subscriber sendNext:@"aa"];
            [subscriber sendCompleted];
        });

        return nil;

    }] deliverOnMainThread] ;
    [sg subscribeNext:^(id  _Nullable x) {

    } error:^(NSError * _Nullable error) {

    }];
}
- (NSString *) zipPath:(NSString*)path{
    //压缩zip文件,压缩文件
    ZipArchive *zip;

    zip = [[ZipArchive alloc] init];
    NSString*createZipPath = [path stringByAppendingPathComponent:@"scene.zip"];

    //判断文件是否存在,如果存在则删除文件
    NSFileManager * fileManager = [NSFileManager defaultManager];
    @try
    {
        if([fileManager fileExistsAtPath:createZipPath])
        {
            if(![fileManager removeItemAtPath:createZipPath error:nil])
            {

            }
        }
    }
    @catch(NSException * exception) {

    }

    [zip CreateZipFile2:createZipPath];

    NSDirectoryEnumerator *dirEnum;

    NSString *file,*str;;

    //遍历这个目录的第一种方法:(深度遍历,会递归枚举它的内容
    dirEnum = [fileManager enumeratorAtPath:path];

    while ((file = [dirEnum nextObject]) != nil)
    {
        //如果为zip文件,则跳过,不加入
        if([file isEqualToString:@"scene.zip"]) continue;
        str = [path stringByAppendingPathComponent:file];
        [zip addFileToZip:str newname:file];
        NSLog(@"%@",str);
    }

    [zip CloseZipFile2];

    return createZipPath;
}

记录下一个异步的栈,有空再补充分析下

__36-[PTLVRSceneSettingsVC uploadScene:]_block_invoke.191 
 -[RACSubscriber sendNext:]  -[RACPassthroughSubscriber sendNext:]  __44-[RACSignal(Operations) deliverOnMainThread]_block_invoke_2.839 
 __44-[RACSignal(Operations) deliverOnMainThread]_block_invoke_3 
 main 
 __44-[RACSignal(Operations) deliverOnMainThread]_block_invoke_2 
 __44-[RACSignal(Operations) deliverOnMainThread]_block_invoke.838 
 -[RACSubscriber sendNext:]  -[RACPassthroughSubscriber sendNext:]  __36-[PTLVRSceneSettingsVC uploadScene:]_block_invoke_2 
 __36-[PTLVRSceneSettingsVC uploadScene:]_block_invoke 
 __30-[RACDynamicSignal subscribe:]_block_invoke 
 -[RACSubscriptionScheduler schedule:]  -[RACDynamicSignal subscribe:]  -[RACSignal(Subscription) subscribeNext:error:completed:]  __44-[RACSignal(Operations) deliverOnMainThread]_block_invoke 
 __30-[RACDynamicSignal subscribe:]_block_invoke 
 -[RACSubscriptionScheduler schedule:]  -[RACDynamicSignal subscribe:]  -[RACSignal(Subscription) subscribeNext:error:]  -[PTLVRSceneSettingsVC uploadScene:]  __39-[PTLVRSceneSettingsVC saveSceneStory:]_block_invoke

猜你在找的React相关文章