Ios 离开uiviewcontrolelr时,Dropbox上载停止
我在dropbox上传中面临问题 当我停留在我已经写了dropbox上传代码的视图上时,它工作得很好。但如果在上传过程中间我离开视图并打开另一个屏幕,则上传停止或取消 我正在使用下面的代码Ios 离开uiviewcontrolelr时,Dropbox上载停止,ios,iphone,dropbox,Ios,Iphone,Dropbox,我在dropbox上传中面临问题 当我停留在我已经写了dropbox上传代码的视图上时,它工作得很好。但如果在上传过程中间我离开视图并打开另一个屏幕,则上传停止或取消 我正在使用下面的代码 - (void)didPressLink { self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]]; self.restClient.delegate = self; if(
- (void)didPressLink {
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
if(![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] linkFromController:self];
}
}
-(void)saveFileOnDropBox{
[self didPressLink];
NSString *filename = [soundOneNew lastPathComponent];
NSString *destDir = @"/";
[[self restClient] uploadFile:filename toPath:destDir withParentRev:nil fromPath:soundOneNew];
}
-(void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
from:(NSString*)srcPath metadata:(DBMetadata*)metadata {
NSLog(@"File uploaded successfully to path: %@ %@", metadata.path, destPath);
[[self restClient] loadSharableLinkForFile: [NSString stringWithFormat:@"/%@",metadata.path]];
}
- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
NSLog(@"File upload failed with error - %@", error);
}
- (void)restClient:(DBRestClient*)restClient loadedSharableLink:(NSString*)link
forFile:(NSString*)path
{
NSLog(@"Sharable link %@",link);
NSLog(@"File Path %@ ",path);
}
-(void) restClient:(DBRestClient *)client uploadProgress:(CGFloat)progress forFile:(NSString *)destPath from:(NSString *)srcPath {
static NSDate* date = nil;
static double oldUploadedFileSize = 0;
if (!date) {
date = [NSDate date] ;
} else {
NSTimeInterval sec = -[date timeIntervalSinceNow];
date = [NSDate date] ;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:srcPath error:nil];
double uploadedFileSize = (double)[fileAttributes fileSize] * progress;
if (sec) {
NSLog(@"speed approx. %.2f KB/s", (uploadedFileSize - oldUploadedFileSize )/1024.0 / sec );
}
oldUploadedFileSize = uploadedFileSize;
self.uploadAudioProgress.progress = progress;
}
}
如何在我离开您呼叫的视图时继续上载过程
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
创建一个新的REST客户端,然后
[[self restClient] uploadFile:filename toPath:destDir withParentRev:nil fromPath:soundOneNew];
做上传。因此,该客户端归视图控制器所有,当视图控制器被销毁时,即当您离开它时,该客户端将被销毁
您需要其他类和它的一个实例(可能是一个单例或一个由应用程序委托拥有并传递给需要它的实例的实例),它拥有所有创建的REST客户端,并将它们保留到它们完成为止。不要让客户端归视图控制器所有…@Wain i dint明白您说的吗