1

before iOS8, I use ALAsset and use buffer to get NSData then upload video like below;

Byte * buffer = (Byte *)malloc(lenght);

NSError * error = nil;

NSUInteger readLength = [self.asset.defaultRepresentation getBytes:buffer fromOffset:self.sendedSize length:lenght error:&error];

NSData * data = [NSData dataWithBytes:buffer length:readLength];

so, how can i upload video use PhotoKit? How can i get the video data?

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
彭显鹤
  • 13
  • 3

1 Answers1

3

How about this:

    PHAsset *videoAsset /*Your video asset */;
    PHVideoRequestOptions *options = /*Options if you need them */;
    [[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
        NSURL *fileURL = /*Create a temporary file URL*/;
        exportSession.outputURL = fileURL;

        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            NSData *assetData = [NSData dataWithContentsOfURL:fileURL];
            /* Do whatever you want to do with this data, and delete it afterwards */      
        }];
    }];
Ladislav
  • 7,223
  • 5
  • 27
  • 31