2016-07-12 16 views
0

私はSwiftで書かれたiOSアプリを通じてVimeoアカウントにビデオをアップロードしようとしています。私のアプリにVimeoUpload SDKを組み込むにはどうすればいいですか? VimeoNetworkingやVIMNetworkingに依存していますか?これらはCocoapodsとして利用できないので、これらのライブラリを含める最良の方法は何ですか?Vimeoアップロードの使い方

+0

こんにちは私はアップロードを実装しようとしたが、そのコールバックにアップロード状況とアップロードされたURLを与えていない、あなたのアップロードのコードを共有してくださいだろうか? –

答えて

-1

私はVimeoで働いています。

VimeoUploadはさらに数週間、limboに入っています。私たちは、Objc <> Swiftの相互運用性とiOS7 <> iOS8 +に関連したいくつかの問題に直面し、VimeoUploadをCocoapodとして利用できないようにしました。

2016年8月中旬までにVimeoUploadをCocoapods経由で入手できる正当なv1.0として利用できるようにすることを意味します。

中間では、ライブラリをgitサブモジュールとして含めることができます。 masterブランチを含めるようにしてください。v1.0ブランチは含まないようにしてください。そして、サブモジュールを「開発ポッド」として設定します。これにより、VIMNetworkingからサブスペックが引き出されます。

他のご質問がありましたら、お手伝いをして幸いです。できるだけ早くv1.0をお試しください。

+0

VimeoUploadライブラリはUIImagePickerController(ビデオを圧縮する)で動作しますか?私はimagepickerコントローラを使用して "UIImagePickerControllerReferenceURL"を取得します。次に、PHAsset.fetchAssetsWithALAssetURLsを使用してPHAssetを取得します。私はその後、READMEで説明されているExportOperationメソッドを使用してビデオをアップロードしようとします。しかし、ビデオは私のVimeoAccountには表示されません。 Xcodeのログに "<記述子識別子>を作成"が表示されていますが、エラーは表示されません。 –

+0

こんにちは、アップロードを実装しようとしましたが、ステータスをアップロードしておらず、コールバックでURLをアップロードしていないので、アップロードコードを共有してください。 –

+0

こんにちは、私はビデオをvimeoにアップロードしたいと思います。客観的なcのライブラリはありますか?私を助けてください。 – Ashu

3
#import <Foundation/Foundation.h> 

@protocol vimeodelagate; 
@interface Vimeo_uploader : NSObject<NSURLSessionDelegate, NSURLSessionTaskDelegate> 

@property(weak) id<vimeodelagate> delegate; 



+(id)SharedManger; 
-(void)pass_data_header:(NSData *)videoData; 
- (void)Give_title_to_video:(NSString *)VIdeo_id With_name:(NSString *)name ; 


@end 

@protocol vimeodelagate <NSObject> 
-(void)vimeouploader_succes:(NSString *)link methodName:(NSString *)methodName; 
-(void)vimeouploader_progress:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalByte; 
-(void)vimeouploader_error:(NSError *)error methodName:(NSString *)methodName; 

@end 




#define Aurtorizartion @"bearer your token" 
#define accept @"application/vnd.vimeo.*+json; version=3.2" 

#import "Vimeo_uploader.h" 

@implementation Vimeo_uploader 


+(id)SharedManger{ 

    static Vimeo_uploader *Vimeouploader = nil; 
    @synchronized (self) { 
     static dispatch_once_t oncetoken; 
     dispatch_once(&oncetoken, ^{ 
      Vimeouploader = [[self alloc] init]; 
     }); 
    } 
    return Vimeouploader; 
} 

-(id)init{ 

    if (self = [super init]) { 

    } 
    return self; 
} 

- (void)pass_data_header:(NSData *)videoData{ 

    NSString *tmpUrl=[[NSString alloc]initWithFormat:@"https://api.vimeo.com/me/videos?type=streaming&redirect_url=&upgrade_to_1080=false"]; 

    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:tmpUrl] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0]; 
    [request setHTTPMethod:@"POST"]; 
    [request setValue:Aurtorizartion forHTTPHeaderField:@"Authorization"]; 
    [request setValue:accept forHTTPHeaderField:@"Accept"];//change this according to your need. 
    NSError *error; 
    NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: &error]; 
    NSDictionary * json = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error]; 

    if (!error) { 
     [self call_for_ticket:[json valueForKey:@"upload_link_secure"] complet_url:[json valueForKey:@"complete_uri"] videoData:videoData]; 

    }else{ 
     NSLog(@"RESPONSE--->%@",json); 
    } 


} 
- (void)call_for_ticket:(NSString *)upload_url complet_url:(NSString *)complet_uri videoData:(NSData *)videoData{ 


    NSURLSessionConfiguration *configuration; 
    //configuration.timeoutIntervalForRequest = 5; 
    //configuration.timeoutIntervalForResource = 5; 
    configuration.HTTPMaximumConnectionsPerHost = 1; 
    configuration.allowsCellularAccess = YES; 
    // configuration.networkServiceType = NSURLNetworkServiceTypeBackground; 
    configuration.discretionary = NO; 
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration 
                  delegate:self 
                delegateQueue:[NSOperationQueue mainQueue]]; 


    NSURL *url = [NSURL URLWithString:upload_url]; 
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; 
    [urlRequest setHTTPMethod:@"PUT"]; 
    [urlRequest setTimeoutInterval:0]; 
    [urlRequest setValue:Aurtorizartion forHTTPHeaderField:@"Authorization"]; 
    [urlRequest setValue:accept forHTTPHeaderField:@"Accept"]; 
    NSError *error; 

    NSString *str_lenth = [NSString stringWithFormat:@"%lu",(unsigned long)videoData.length]; 
    NSDictionary *dict = @{@"str_lenth":str_lenth, 
          @"Content-Type":@"video/mp4"}; 
    NSData *postData12 = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error]; 
    [urlRequest setHTTPBody:postData12]; 
    // [urlRequest setHTTPBody:videoData]; 



    // You could try use uploadTaskWithRequest fromData 
    NSURLSessionUploadTask *taskUpload = [session uploadTaskWithRequest:urlRequest fromData:videoData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

     NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response; 
     if (!error && httpResp.statusCode == 200) { 
      [self call_complete_uri:complet_uri]; 
     } else { 
      if([self.delegate respondsToSelector:@selector(vimeouploader_error:methodName:)]){ 
       [self.delegate vimeouploader_error:error methodName:@"vimeo"];} 
      NSLog(@"ERROR: %@ AND HTTPREST ERROR : %ld", error, (long)httpResp.statusCode); 
     } 
    }]; 
    [taskUpload resume]; 


} 
-(void)call_complete_uri:(NSString *)complettion_url{ 


    NSString *str_url =[NSString stringWithFormat:@"https://api.vimeo.com%@",complettion_url]; 
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:str_url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0]; 
    [request setHTTPMethod:@"DELETE"]; 
    [request setValue:Aurtorizartion forHTTPHeaderField:@"Authorization"]; 
    [request setValue:accept forHTTPHeaderField:@"Accept"]; 
    //change this according to your need. 

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
     NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
      if ([httpResponse statusCode] == 201) { 
       NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:[httpResponse allHeaderFields]]; 
       if (dict) { 
        if([self.delegate respondsToSelector:@selector(vimeouploader_succes:methodName:)]){ 
        // [self.delegate vimeouploader_succes:[dict valueForKey:@"Location"] methodName:@"vimeo"]; 
         NSLog(@"sucesses"); 

         NSString *str = [NSString stringWithFormat:@"title"]; 
         [self Give_title_to_video:[dict valueForKey:@"Location"] With_name:str]; 



        }else{ 
         if([self.delegate respondsToSelector:@selector(vimeouploader_error:methodName:)]){ 
          [self.delegate vimeouploader_error:error methodName:@"vimeo"];} 
        } 
       } 
      }else{ 
       //9 
       if([self.delegate respondsToSelector:@selector(vimeouploader_error:methodName:)]){ 
        [self.delegate vimeouploader_error:error methodName:@"vimeo"];} 
       NSLog(@"%@",error.localizedDescription); 
      } 
    }]; 

} 
- (void)Give_title_to_video:(NSString *)VIdeo_id With_name:(NSString *)name { 

    NSString *tmpUrl=[[NSString alloc]initWithFormat:@"https://api.vimeo.com%@",VIdeo_id]; 

    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:tmpUrl] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0]; 
    [request setHTTPMethod:@"PATCH"]; 
    [request setValue:Aurtorizartion forHTTPHeaderField:@"Authorization"]; 
    [request setValue:accept forHTTPHeaderField:@"Accept"];//change this according to your need. 
    NSError *error; 
    NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: &error]; 
    NSDictionary * json = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error]; 
    NSString *str_description = @"description"; 
    NSDictionary *dict = @{@"name":name, 
          @"description":str_description, 
          @"review_link":@"false" 
          }; 

    NSData *postData12 = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error]; 
    [request setHTTPBody:postData12]; 

    if (!error) { 
     NSLog(@"RESPONSE--->%@",json); 

     [self.delegate vimeouploader_succes:[json valueForKey:@"link"] methodName:@"vimeo"]; 
    }else{ 
     if([self.delegate respondsToSelector:@selector(vimeouploader_error:methodName:)]){ 
      [self.delegate vimeouploader_error:error methodName:@"vimeo"];} 
     //NSLog(@"%@",error.localizedDescription); 
     NSLog(@"Give_title_to_video_error--->%@",error); 
    } 


} 
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend { 

    NSLog(@"didSendBodyData: %lld, totalBytesSent: %lld, totalBytesExpectedToSend: %lld", bytesSent, totalBytesSent, totalBytesExpectedToSend); 
    if([self.delegate respondsToSelector:@selector(vimeouploader_progress:totalBytesExpectedToSend:)]){ 
     [self.delegate vimeouploader_progress:totalBytesSent totalBytesExpectedToSend:totalBytesExpectedToSend];} 
} 



- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { 
    if (error == nil) { 
     NSLog(@"Task: %@ upload complete", task); 
    } else { 
     NSLog(@"Task: %@ upload with error: %@", task, [error localizedDescription]); 
    } 
} 
@end 
+0

コードは機能していますが、ビデオのタイトルと説明が設定されていません。 @Mahesh Joya –

関連する問題