文档上传说明

@文档上传接入

  • 1.设置info.plist文件

    • 以Source Code方式打开info.plist文件sourceCode,在里面加入这段代码

      <key>CFBundleDocumentTypes</key>
      <array>
      <dict>
         <key>CFBundleTypeExtensions</key>
         <array>
             <string>pptx</string>
         </array>
         <key>CFBundleTypeIconFiles</key>
         <array>
             <string>icon@2x.png</string>
             <string>icon@3x.png</string>
         </array>
         <key>CFBundleTypeName</key>
         <string>PPT Document</string>
         <key>LSHandlerRank</key>
         <string>Default</string>
         <key>LSItemContentTypes</key>
         <array>
             <string>com.microsoft.powerpoint.​ppt</string>
         </array>
      </dict>
      <dict>
         <key>CFBundleTypeExtensions</key>
         <array>
             <string>doc</string>
             <string>docx</string>
         </array>
         <key>CFBundleTypeIconFiles</key>
         <array>
             <string>icon@2x.png</string>
             <string>icon@3x.png</string>
         </array>
         <key>CFBundleTypeName</key>
         <string>DOC Document</string>
         <key>LSHandlerRank</key>
         <string>Default</string>
         <key>LSItemContentTypes</key>
         <array>
             <string>com.microsoft.word.doc</string>
         </array>
      </dict>
      <dict>
         <key>CFBundleTypeExtensions</key>
         <array>
             <string>pdf</string>
         </array>
         <key>CFBundleTypeIconFiles</key>
         <array>
             <string>icon@2x.png</string>
             <string>icon@3x.png</string>
         </array>
         <key>CFBundleTypeName</key>
         <string>PDF Document</string>
         <key>LSHandlerRank</key>
         <string>Default</string>
         <key>LSItemContentTypes</key>
         <array>
             <string>com.microsoft.powerpoint.ppt</string>
             <string>public.item</string>
             <string>com.microsoft.word.doc</string>
             <string>com.adobe.pdf</string>
             <string>com.microsoft.excel.xls</string>
             <string>public.image</string>
             <string>public.content</string>
             <string>public.composite-content</string>
             <string>public.archive</string>
             <string>public.audio</string>
             <string>public.movie</string>
             <string>public.text</string>
             <string>public.data</string>
         </array>
      </dict>
      </array>    
  • 2.在appDelegate.m文件里面引入头文件#import "TalkfunImportDocumentViewController.h",添加以下方法

    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if (![self.login isLogin]) {
       [[NSFileManager defaultManager] removeItemAtURL:url error:nil];
       UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未登录不能上传文件" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
       [alert show];
       return NO;
    }
    if (url != nil && [url isFileURL]) {
       UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
       TalkfunImportDocumentViewController * importVC = [storyboard instantiateViewControllerWithIdentifier:@"importController"];
    
       TalkfunLoginNavigationController * nav = (TalkfunLoginNavigationController *)self.window.rootViewController;
       if ([nav.viewControllers.lastObject isKindOfClass:[TalkfunImportDocumentViewController class]]) {
           //            [self.window.rootViewController presentViewController:importVC animated:YES completion:nil];
           importVC = nav.viewControllers.lastObject;
           [importVC addFile:url];
       }else if(![nav.viewControllers.lastObject isKindOfClass:[TalkfunLiveController class]]) {
    
           [nav pushViewController:importVC animated:YES];
           [importVC addFile:url];
       }else if ([nav.viewControllers.lastObject isKindOfClass:[TalkfunLiveController class]]){
           TalkfunLiveController * liveVC = nav.viewControllers.lastObject;
           [liveVC uploadFile:url];
       }
    }
    return YES;
    }
    • 3.引入Module/UploadFile文件夹的全部东西

Finish

@上传说明

  • 状态码
TalkfunCloudLiveCodeSuccess                = 0        成功
TalkfunCloudLiveCodeUploading             = 500    文件正在上传
TalkfunCloudLiveCodeHasBeenUploaded         = 501    文件已经上传过
TalkfunCloudLiveCodeInTheProcessing     = 33    文件处理中
TalkfunCloudLiveCodeProcessFial            = 34     文件处理失败
TalkfunCloudLiveCodeUploadFail            = 503    文件上传失败
  • 上传调用
    • 调用TalkfunDocument.h的以下接口,如果上传到当前帐号,courseID参数传入"0",如果想传入到相应的课程则传入课程的ID,files参数是传入文档的路径集合。
//提供courseID和文件(本地图片的asset(PHAsset或者ALAsset类型)的对象的集合 或 文件的地址) 上传图片或文档,返回上传结果
- (void)upload:(NSString *)courseID files:(NSArray *)files callback:(void (^)(id result))callback;

callback返回的数据:

  • 文档上传中
{
    code = 500;
    progress = "<NSProgress: 0x17013ebe0> : Parent: 0x0 / Fraction completed: 0.0208 / Completed: 32768 of 1576114  ";
    type = document;
}
  • 文档上传完成
{
    code = 0;
    responseObject =     {
        code = 0;
        data =         {
            bid = 12526;
            "client_ip" = "219.136.204.204";
            "course_id" = 0;
            ext = doc;
            filemd5 = 531561e09d6101b2f5cb11dacead5c86;
            from = 1;
            id = 129484;
            location = 1;
            md5 = 531561e09d6101b2f5cb11dacead5c86;
            name = "\U50bb.\U903c.\U5fc3.31";
            "partner_id" = 20;
            pid = 20;
            sid = 2;
            sign = 4673b7e5beb39b9627074fad666abdfd;
            size = 1575936;
            t = 1491031650;
            type = 2;
        };
        timestamp = 1491031656;
    };
    type = document;
}
  • 文档已经上传过

    {
    code = 501;
    msg = "\U8be5\U6587\U6863\U5df2\U7ecf\U4e0a\U4f20\U8fc7";
    responseObject =     {
      bid = 12526;
      "course_id" = 0;
      ext = doc;
      from = 1;
      id = 129485;
      location = 1;
      md5 = 19c9bd8d24daaeaeafa608e7adcfc9ea;
      name = "\U50bb.\U903c.\U5fc3.32";
      origin = "";
      pages = 2;
      "partner_id" = 20;
      sid = 2;
      size = 1575424;
      thumb = "https://lp2-4.talk-fun.com/doc/19/c9/bd/8d24daaeaeafa608e7adcfc9ea/thumb.jpg";
      type = 2;
      url = "https://lp2-4.talk-fun.com/doc/19/c9/bd/8d24daaeaeafa608e7adcfc9ea";
    };
    type = document;
    }
    • 文档上传失败
{
    @"code":503;
    @"msg":error,@"type":@"document"
}
  • 文档处理中
{
    code = 33;
    data =     {
        percent = "83.7";
    };
    msg = "\U6587\U6863\U6b63\U5728\U5904\U7406\U4e2d";
}
  • 文档处理成功
{
    cache = 1;
    code = 0;
    data =     {
        bid = 12526;
        "convert_server" = 3232236136;
        "course_id" = 0;
        donetime = 1491031672;
        ext = doc;
        from = 1;
        id = 129484;
        images = 2;
        info = "";
        location = 1;
        md5 = 531561e09d6101b2f5cb11dacead5c86;
        name = "\U50bb.\U903c.\U5fc3.31";
        pages = 2;
        pid = 20;
        roomid = 550481;
        sid = 2;
        size = 1575936;
        status = 0;
        time = 1491031656;
        type = 2;
        url = "http://lp2-4.talk-fun.com/doc/53/15/61/e09d6101b2f5cb11dacead5c86";
        urlLocal = "http://lp2-4.talk-fun.com/doc/53/15/61/e09d6101b2f5cb11dacead5c86";
    };
}
  • 文档处理失败
{
    code = 34;
    msg = "\U6587\U6863\U6b63\U5728\U5904\U7406\U4e2d";
}
Copyright Talkfun all right reserved,powered by Gitbook修订时间: 2020-05-27 14:16:39

results matching ""

    No results matching ""