Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

ios - Change saving video to photo library to PHPhotoLibrary

I have an iOS app that I am trying to update. In the passed I used UIPhotoLibrary but now I have to switch to PHPhotoLibray. I have done some of the updating but I am stuck.
Could someone please help me. Here is my code

PHPhotoLibrary *library = [[PHPhotoLibrary alloc] init];
        CLLocation *loc = [[CLLocation alloc]initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
        
        NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
        NSLog(@"metadata;%@",[metadata description]);
         NSMutableDictionary *metadataAsMutable = [metadata mutableCopy];
        
       
        
        NSMutableDictionary *GPSDictionary = [[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy];
        
        if(!GPSDictionary)
        {
            GPSDictionary = [NSMutableDictionary dictionary];
        }
        
        
        
        NSError *error = nil;
       [metadataAsMutable setObject:loc forKey:(NSString *)kCGImagePropertyGPSDictionary];
       
         movieData = [NSKeyedArchiver archivedDataWithRootObject:metadataAsMutable requiringSecureCoding:NO error:&error];
        NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:metadataAsMutable requiringSecureCoding:NO error:&error];
        NSURL *assetURL2 = [NSURL URLWithDataRepresentation:myData relativeToURL:movieURL];
        NSLog(@"netadataAsMutable;%@",[metadataAsMutable description]);

//RIGHT HERE ERROR SAYS No visible @interface for 'PHPhotoLibrary' declares the selector 'writeVideoAtPathToSavedPhotosAlbum:completionBlock:' what do I use?

        [library writeVideoAtPathToSavedPhotosAlbum:(NSURL *)movieURL
                                           completionBlock:^(NSURL *assetURL, NSError *error){
                                               if (error) {
                                                   NSLog(@"Save video fail:%@",error);
                                               } else {
                                                   NSLog(@"Save video succeed.");
                                                   
                                                   NSLog(@"assetURL2%@",assetURL2);
                                                  
                                                   [self getsavedvideo];
                                               }
                                               
                                           }];
        

//RIGHT HERE SAYS No visible @interface for 'PHPhotoLibrary' declares the selector 'assetForURL:resultBlock:failureBlock:' What do I change?

        [library assetForURL:movieURL resultBlock:^(PHAsset *asset) {
            // If asset exists
            if (asset) {
                NSLog(@"asset exists");
            } else {
            NSLog(@"no asset exists");
                
            }
        } failureBlock:^(NSError *error) {
            // Type your code here for failure (when user doesn't allow location in your app)
        }];
      
   }
    

I would really appreciate everyones help. Thanks

question from:https://stackoverflow.com/questions/66054149/change-saving-video-to-photo-library-to-phphotolibrary

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...