iOS 获得图片的时间(通过拍照和取出)

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {

    

    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera) {


        

        //照片mediaInfo

        NSDictionary * imageMetadata = info[@"UIImagePickerControllerMediaMetadata"];

        NSDictionary *tIFFDictionary =  [imageMetadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];

        NSString * pictureTime = tIFFDictionary[@"DateTime"];//2016:01:05 11:45:36

        NSLog(@"pictureDate = %@",pictureTime);

        

    } else if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary){

        NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

        [library assetForURL:assetURL

                 resultBlock:^(ALAsset *asset)  {

                     NSDate* pictureDate = [asset valueForProperty:ALAssetPropertyDate];

                     NSDateFormatter * formatter = [[NSDateFormatter alloc]init];

                     formatter.dateFormat = @"yyyy:MM:dd HH:mm:ss";

                     formatter.timeZone = [NSTimeZone localTimeZone];

                     NSString * pictureTime = [formatter stringFromDate:pictureDate];

                     NSLog(@"pictureDate = %@",pictureTime);

                     

                 }

                failureBlock:^(NSError *error) {

        }];

    }


    [picker dismissModalViewControllerAnimated: NO];

}

你可能感兴趣的:(iOS,相关,杂文)