2016-06-17 2 views
1
  • Xcodeの7
  • スウィフト2
  • のObjective C

私はいくつかのObjective Cのコードを変更している、と私はすべてのObjective Cの構文を知りません。 Objective Cのではは交換UISaveVideoAtPathToSavedPhotosAlbum @selector videoSaved機能

NSString *tempFilePath = [downloadURL path]; 
    NSError * error = nil; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder 
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/Videos"]; 
    //NSString *newPath = [[tempFilePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:AvailableVideos[0]]; 
    NSString *newPath = [dataPath stringByAppendingPathComponent:AvailableVideos[0]]; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 

    if (![fileManager fileExistsAtPath:dataPath]) 
     [fileManager createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder 

    //copying temp video to Documents Directory 
    if ([fileManager fileExistsAtPath:newPath] == YES) 
     [fileManager removeItemAtPath:newPath error:&error]; 
    [fileManager copyItemAtPath:tempFilePath toPath:newPath error:&error]; 

:私のアプリのデータコンテナドキュメントディレクトリに映像を保存しているコードで

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(newPath)) 
    // Copy it to the camera roll. 
    UISaveVideoAtPathToSavedPhotosAlbum(newPath, self, @selector(videoSaved:didFinishSavingWithError:contextInfo:), (__bridge void *)(AvailableVideos[0])); 

else 
{ 
    [self ErrorOnDownloadOrSave]; 
    return; 
} 

:私はカメラロールにビデオを保存して、次のコードを交換しました「videoSaved」イベントが完了したときに呼び出されObjective Cの「機能」があるiOSのカメラロールに保存されているコード:

-(void)videoSaved:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ 
    //implementation 
} 

私が呼び出す方法を把握する必要がありこのコードの後に​​、この「機能」、「videoSaved」:

//copying temp video to Documents Directory 
     if ([fileManager fileExistsAtPath:newPath] == YES) 
      [fileManager removeItemAtPath:newPath error:&error]; 
     [fileManager copyItemAtPath:tempFilePath toPath:newPath error:&error]; 

私はvideoSaved機能がUISaveVideoAtPathToSavedPhotosAlbumのための特別な署名であるが、私は、私は新しい関数を記述するのか分からないのObjective Cでちょうどそう不慣れだ実現私が呼び出すことができ、私のエラーオブジェクトを渡し、videoSavedの実装を維持します。

答えて

0

NSFileManager文書によると、方法copyItemAtPathはBOOLを返します。

アイテムが正常にコピーされたか、ファイルマネージャの代理人が意図的に操作を停止した場合は、YESです。エラーが発生した場合はNOを返します。

if ([fileManager copyItemAtPath:tempFilePath toPath:newPath error:&error]) { 
     //saved 
     NSLog(@"video saved"); 
} else { 
     //error 
     NSLog(@"error occured : %@", error); 
} 

だからあなたのような何かを行うことができます

関連する問題