【问题标题】:UIImagePickerController - picking video in background from photo libraryUIImagePickerController - 从照片库中挑选背景视频
【发布时间】:2016-10-03 08:40:34
【问题描述】:

如何在后台模式下继续从照片库中挑选视频?

我的意思是当我从imagePickerController - PhotoLibrary 按下use 按钮并开始压缩视频 - 在此压缩过程中(附上截图)如果我按下home button(i.e. go to background) 然后来到foreground 然后我得到@ 987654327@ 为null,那么应用程序是否有可能在后台继续压缩视频并在到达foreground 时返回正确的url

截图:

我的didFinishPickingMediaWithInfo

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{


NSURL *url = info[UIImagePickerControllerMediaURL];

NSLog(@"url : %@",url);

[picker dismissViewControllerAnimated:YES completion:nil];

}

P.S : 如果我们通过camera 录制视频并转到后台,那么它将在那里停止录制,我们可以在进入前台后使用它。

我已经想到了一种解决方法 - UIBackgroundTaskIdentifier,但它不会在所有情况下都有效,如果视频很大,那么它有时间限制,所以寻找任何其他解决方案!

任何帮助将不胜感激! :)

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller


    【解决方案1】:

    如果我们想在video is compressing and user press home button(app go in background) 期间通过UIImagePickerControllerphotolibrary 在后台连续选择video,那么我们必须使用UIBackgroundTaskIdentifier 在后台继续执行或任何其他让应用程序在后台运行的后台方式(不太可能的事情!)。现在,UIBackgroundTaskIdentifier 有时间限制,所以我们不能选择任何大小的视频,所以如果我们限制视频持续时间,那么我们可以在后台连续选择它,例如,

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.videoMaximumDuration = 60.0;
    
     self.backgroundTask = UIBackgroundTaskInvalid;
    
                self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
                    NSLog(@"Background handler called. Not running background tasks anymore.");
                    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
                    self.backgroundTask = UIBackgroundTaskInvalid;
                }];
    
    [self presentViewController:picker animated:YES completion:NULL]; 
    

    有了UIImagePickerController,我们只能在后台挑选视频。如果有人想在后台选择大视频,那么他/她应该看看ALAssetLibraryPhotos framework

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 2014-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多