Ios 如何使用Vimeo上传
我正试图通过一个用Swift编写的iOS应用程序将视频上传到Vimeo帐户。如何将VimeOutload SDK合并到我的应用程序中?它依赖于VimeNetworking还是VimeNetworking?既然这些库不能作为cocoapod提供,那么包含这些库的最佳方式是什么?我为Vimeo工作 维米奥普洛德还有几个星期没有行动。我们遇到了一系列与Objc Swift互操作性和iOS7 iOS8+相关的问题,这些问题阻止我们将VimeOutload作为Cocoapod提供 我们计划从2016年7月下旬开始开展这项工作。这意味着到2016年8月中旬,VimeOutload将作为合法的v1.0版本通过Cocoapods提供 在此期间,您可以将库作为git子模块包含。确保包含Ios 如何使用Vimeo上传,ios,vimeo,vimeo-api,vimeo-ios,Ios,Vimeo,Vimeo Api,Vimeo Ios,我正试图通过一个用Swift编写的iOS应用程序将视频上传到Vimeo帐户。如何将VimeOutload SDK合并到我的应用程序中?它依赖于VimeNetworking还是VimeNetworking?既然这些库不能作为cocoapod提供,那么包含这些库的最佳方式是什么?我为Vimeo工作 维米奥普洛德还有几个星期没有行动。我们遇到了一系列与Objc Swift互操作性和iOS7 iOS8+相关的问题,这些问题阻止我们将VimeOutload作为Cocoapod提供 我们计划从2016年7月
master
分支,而不是v1.0
分支。然后将子模块设置为“开发吊舱”。这将从VIMNetworking中引入一个子集
如果您还有其他问题,请告诉我,很乐意帮助/尝试尽快完成v1.0 我为维梅奥工作
#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
维米奥普洛德还有几个星期没有行动。我们遇到了一系列与Objc Swift互操作性和iOS7 iOS8+相关的问题,这些问题阻止我们将VimeOutload作为Cocoapod提供
我们计划从2016年7月下旬开始开展这项工作。这意味着到2016年8月中旬,VimeOutload将作为合法的v1.0版本通过Cocoapods提供
在此期间,您可以将库作为git子模块包含。确保包含master
分支,而不是v1.0
分支。然后将子模块设置为“开发吊舱”。这将从VIMNetworking中引入一个子集
如果您还有其他问题,请告诉我,很乐意帮助/尝试尽快完成v1.0 #导入
#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
@vimeodelagate方案;
@接口Vimeo_上传器:NSObject
@属性(弱)id委托;
+(id)共享愤怒;
-(无效)传递数据头:(NSData*)视频数据;
-(无效)为视频(NSString*)提供视频id(名称:(NSString*)名称;
@结束
@vimeodelagate协议
-(void)VimeOutloader_成功:(NSString*)链接方法名:(NSString*)方法名;
-(void)VimeOutloader\u progress:(int64\u t)totalBytesSent totalBytesExpectedToSend:(int64\u t)totalByte;
-(void)VimeOutloader_error:(NSError*)error methodName:(NSString*)methodName;
@结束
#定义Aurtorization@“您的代币持有人”
#定义accept@“application/vnd.vimeo.*+json;version=3.2”
#导入“Vimeo_uploader.h”
@Vimeo_上传器的实现
+(id)共享愤怒{
静态Vimeo_上传器*VimeOutloader=nil;
@同步(自){
静态调度一次;
一次发送(一次发送)^{
VimeOutloader=[[self alloc]init];
});
}
返回VimeOutloader;
}
-(id)init{
if(self=[super init]){
}
回归自我;
}
-(无效)传递数据头:(NSData*)视频数据{
NSString*tmpUrl=[[NSString alloc]initWithFormat:@”https://api.vimeo.com/me/videos?type=streaming&redirect_url=&upgrade_to_1080=false"];
NSMutableURLRequest*request=[NSMutableUrlRequestWithURL:[NSURL URLWithString:tmpUrl]cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0];
[请求设置HttpMethod:@“POST”];
[请求设置值:HttpHeaderField的授权:@“授权”];
[请求设置值:accept forHTTPHeaderField:@“accept”];//根据需要更改此设置。
n错误*错误;
NSData*returnData=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSDictionary*json=[NSJSONSerialization JSONObjectWithData:returnData选项:针织错误:&错误];
如果(!错误){
[json valueForKey:@“上传链接安全”]complett\u url:[json valueForKey:@“完成uri”]videoData:videoData];
}否则{
NSLog(@“响应->%@”,json);
}
}
-(无效)调用\u获取票证:(NSString*)上载\u url完成\u url:(NSString*)完成\u uri视频数据:(NSData*)视频数据{
NSURLSessionConfiguration*配置;
//configuration.timeoutitervalforrequest=5;
//configuration.timeoutitervalforresource=5;
configuration.HTTPMaximumConnectionsPerHost=1;
configuration.allowscellaraccess=是;
//configuration.networkServiceType=NSURLNetworkServiceTypeBackground;
configuration.decreative=否;
NSURLSession*session=[NSURLSession sessionWithConfiguration:configuration
代表:赛尔夫
delegateQueue:[NSOperationQueue mainQueue]];
NSURL*url=[NSURL URLWithString:upload_url];
NSMutableURLRequest*urlRequest=[NSMutableUrlRequestWithURL:url];
[urlRequestSetHttpMethod:@“PUT”];
[urlRequest setTimeoutInterval:0];
[urlRequest设置值:HttpHeaderField的授权:@“授权”];
[urlRequest setValue:accept forHTTPHeaderField:@“accept”];
n错误*错误;
NSString*STRU lenth=[NSString stringWithFormat:@“%lu”,无符号长)videoData.length];
NSDictionary*dict={“stru lenth”:stru lenth,
@“内容类型”:@“视频/mp4”};
NSData*postData12=[NSJSONSerialization dataWithJSONObject:dict选项:0错误:&错误];
[UrlRequestSetHttpBody:postData12];
//[UrlRequestSetHttpBody:videoData];
//您可以尝试使用UploadTaskWithRequestfromData
NSURLSessionUploadTask*taskUpload=[session uploadTaskWithRequest:UrlRequestFromData:videoData completionHandler:^(NSData*数据,NSURLRResponse*响应,NSError*错误){
NSHTTPURLResponse*httpResp=(NSHTTPURLResponse*)响应;
如果(!error&&httpResp.statusCode==200){
[self call_complete_uri:complete_uri];
}否则{
if([self.delegate respondsToSelector:@selector(VimeOutloader_错误:methodName:)])){
[self.delegate vimeoploader_error:error methodName:@“vimeo”];}
NSLog(@“错误:%@和