UIImagePickerController - picking video in background from photo library - ios

How to continue picking video from photo library in background mode ?
I mean when I press use button from imagePickerController - PhotoLibrary and video is started to get compressing - During this compression process (have attached screenshot) if I press home button(i.e. go to background) and then come to foreground then I got info[UIImagePickerControllerMediaURL] as null, so is it possible that app can continue compressing video in background also and return proper url when come to foreground ?
Screenshot :
My didFinishPickingMediaWithInfo,
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSURL *url = info[UIImagePickerControllerMediaURL];
NSLog(#"url : %#",url);
[picker dismissViewControllerAnimated:YES completion:nil];
}
P.S : If we record video by camera and go to background then it will stop recording there and we can use it after coming foreground.
I have thought of one workaround - UIBackgroundTaskIdentifier but it will not work in every case, if video is big then it have time limit, so looking for any other solution!
Any help will be appreciated! :)

IF we want to pick video continuously in background by UIImagePickerController from photolibrary during video is compressing and user press home button(app go in background) then we have to use UIBackgroundTaskIdentifier for continue execution in background or any other background way which keeps app working in background(less possible thing!). Now, UIBackgroundTaskIdentifier has time limit so we can't pick any size of video, so if we restricted video time duration then we can pick it continuously in background something like,
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];
With UIImagePickerController we can do that much only to pick video in background. If anyone want to pick large video in background then he/she should take look into ALAssetLibrary or Photos framework.

Related

Can I filter out songs downloaded to device from Apple Music?

I have a MPMediaPickerController showing songs available on the device to use for sending to other users on my app. I've filtered out Cloud items, but I also want to filter out songs from Apple Music that have been made "available offline."
-(void)openMusic:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"myMusic"]){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.75 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.showsCloudItems = NO;
[self presentViewController:mediaPicker animated:YES completion:nil];
});
}
}
Currently, it's still showing all downloaded Apple Music tracks. How can I filter them out?
According to this answer, if you use:
picker.showsCloudItems = NO;
You will get the list of songs that either were manually downloaded in the Music app or songs that were streamed and therefore cached.
However, since Apple Music songs are DRM protected, to display only songs downloaded locally, you need to add this line, too:
picker.showsItemsWithProtectedAssets = NO;

Intermittent crash after UIImagePickerController with camera

We have an app that is working stable, but occasionally users report that they get crashes when they use the function to take a picture with the camera.
The problem is that the crash seems to happen just when UIImagePickerController is closed and the control is returned to the app.
We set the delegate when the pickerController is loaded
- (IBAction)popupShootPhoto:(id)sender {
// Detect if camera is available, otherwise exit
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
return;
}
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:nil];
}
When the app resumes, the photo is normally processed in the callback to the regular delegate method.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
The problem is that we cannot reproduce the problem. All we have to work from are the crash logs that we have available in the organizer from the devices.
This is what the crashing thread typically look like, there are no references to our own code, so we have not much to work from.
Can anyone suggest an approach to resolve or troubleshoot problems like this? The problem has been the same on both iOS 9 and still exists on iOS 10.

Is it possible to place a static image on top of the webview in a Cordova applicaiton

My case is the following: I have a Cordova application that has to run on iOS. I have to prevent sensitive information from being shown in the app switcher when the app is being in background.
Apple provides this solution for native applications which doesn't seem to solve my problem, because it doesn't manipulate the web view in any way.
I wonder if I can natively place some static image covering the webview. As I understand the system takes a screenshot of the view right after the applicationDidEnterBackground: method is invoked.
This way the system will take a screenshot of the image I put on top instead of the actual content of the webview.
I'm not an experienced iOS developer and I will appreciate any suggestion.
Thanks.
It turned out apple's solution could fix the problem with a small edit from me.
Instead of implementing
- (void)applicationDidEnterBackground:(UIApplication *)application
I implemented
-(void)applicationWillResignActive:(UIApplication *)application
Then no matter if you hit the home button once or twice, it will cover the viewcontroller with the blank one just created.
-(void)applicationWillResignActive:(UIApplication *)application {
UIViewController *blankViewController = [UIViewController new];
//this is how to attach image
UIImage *splashImage = [UIImage imageNamed:#"some image"];
blankViewController.view.backgroundColor = [UIColor colorWithPatternImage: splashImage];
// set some transition style
blankViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self.window.rootViewController presentViewController:blankViewController animated:YES completion:NULL];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}

how to notify user for approaching VideoMaximumDuration

I am using a UIImagePickerController for recording a 30 second video.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.videoMaximumDuration=30.0f;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
I want an alarm type notification for user to notify user that video recording time is about to complete.
For example, if my timer for video recording completes 25s then an alarm is started for notifying user that video recording is about to finish at 30 seconds.
Using videoMaximumDuration method you can restrict length of video from both ways. Like if you are recording video an alert will popup saying you cannot record video more than 60 sec and if you are selecting any video file from your library, first it will check the length of your video if length is more than 60 sec. Again alert will popup saying video is larger than 60 sec but there will be two options i.e. use or cancel. If you select use then it will crop the length of video upto 60sec from the beginning.
imagePickerController.videoMaximumDuration = 60.0f;

ios UIImagePickerController delay switching to front camera in the first time

I have implemented to launch UIImagePickerController to capture picture. At the first time, rear camera appear fast, then I switch to front camera, it responses very slowly. It seems to take me nearly 15 seconds. I don't know why initing front camera so slow.
Here my code
UIImagePickerController * _picker = nil;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_picker = [[[UIImagePickerController alloc] init] autorelease];
_picker.delegate = self;
_picker.allowsEditing = NO;
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:_picker animated:YES];
}
UPDATE: My device is iPad 2 (iOS 7.0), I also test Facebook app on my device, it responses immediately when I switch to front camera. When I test my app on Ipad mini (iOS 6.1.3), it works very well, this problem doesn't happen. Can someone figure me out, it's little missing when initialize UIImagePickerController, I suppose.
UPDATE 2: I wrote an another very simple project. It launches an UIImagePickerController immediately on viewDidLoad of the rootViewController and it works well, UIImagePickerController responses instantly when I switch to front camera. Does anyone have idea for it?
Do this on new thread would cancel the delay on open url. I bet it is the same delay.
Note: Not yet tested on camera.
[NSThread detachNewThreadSelector:#selector(openbrowser_in_background:) toTarget:self withObject:Object];
- (void)openbrowser_in_background:(NSString *)url
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url]];
}
And you might like to change the openURL to
[self presentModalViewController:_picker animated:YES];

Resources