Objective-C iPhone - UIImagePickerController error - iphone

I'm doing something with UIImagePickerController.
It works fine and the Picture browser does open, however, I get this message.
"Failed to save the videos metadata to the filesystem. Maybe the information did not conform to a plist."
What could be causing that? That is caused by this line
[self presentModalViewController:self.imgPicker animated:YES]; which is activated on a button click
Snippets of the code that I have below.
- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = YES;
self.imgPicker.delegate = self;
}
- (IBAction)grabImage {
[self presentModalViewController:self.imgPicker animated:YES];
}
Thanks,
Tee

Many people have seen that error. It appears to not actually have any negative impact on your app, however. So don't worry about and hope Apple fixes it in the next SDK.
Here's a thread on the Apple dev forums about it (Apple iPhone developer account required)
https://devforums.apple.com/message/144567#144567
No solutions have turned up to my knowledge.

Related

Crash / Memory Warning when taking a picture - iPhone

I am getting a memory warning and the app is crashing during the time when a photo is taken with the iPhone. Not sure how to address this because the code that opens the camera works - and the code after a picture is captured works, but the error is somewhere in the camera taking a picture section of the app...
I'm starting the camera like this:
imagePicker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
} else if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
I am getting "Received memory warning." right before Recorder_SourceStarted and AVCaptureDeviceDidStartRunningNotification.
I then get Recorder_DidStartPreviewing, Recorder_FlashStateChanged, Recorder_DidStartFocusOperation, Recorder_DidCompleteFocusOperation, Recorder_FlashStateChanged, Recorder_WillCapturePhoto, Recorder_DidCapturePhoto, and Recorder_PhotoStillImageSampleBufferReady before the app crashes.
Recorder_PhotoStillImageSampleBufferReady is the last notification I am getting before the app crashes. It doesn't make it to _UIImagePickerControllerUserDidCaptureItem at which point the app starts running code I wrote again.
Sometimes it doesn't crash... I get the memory warning and the app continues working as it should, but the potential is there for a crash because of this memory warning and I'm getting crashes in testing so I'd like to figure out what is causing this and fix it.
Any help would be great! Thanks!
I was alloc'ing tableViews in the app (not dealloc'ing because it's using ARC) and apparently after the calls to alloc tableViews had been made, trying to capture a picture would cause a memory crash. I changed it to set the .hidden property on the tableviews on and off when users needed to see the table instead of alloc'ing each time a tableview was requested and now the app never crashes when a picture is taken. Sometimes there is still a memory warning, but never a crash, and often no memory warning at all when I take a picture.

MPMediaPickerController.showsCloudItems seems to do nothing

Posted this on Apple with no luck, but now that the iOS 6 NDA is up, hoping more eyes will see it here.
I am attempting to modify an app to only allow a user to select music that has been downloaded locally. I have the following code under iOS 6 GM:
MPMediaPickerController* mpc = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mpc.allowsPickingMultipleItems = YES;
mpc.modalPresentationStyle = UIModalPresentationCurrentContext;
mpc.showsCloudItems = NO;
[self presentViewController:mpc animated:YES completion:nil];
From the documentation:
The default behavior for a media item picker is YES, which means the
the picker shows available iCloud items. A media item is considered an
iCloud item if it is available via iTunes Match and is not already
stored on the device.
I take this to mean that if iTunes Match is enabled, only items that have been downloaded to the device will show in the picker, however I always see the entire iTunes Match library. I filed a radar for this, because it seems like a serious bug. If anyone can tell me otherwise, I'd love to know what I'm missing here.
This seems to be an OS problem.
Using picker.showsCloudItems = NO; correctly shows fewer songs, instead of the whole list... The songs listed there are songs that either were manually downloaded in the Music app or songs that were streamed and therefore cached.
The problem, at least in my case, is dealing with the cached ones.
If I select a song that was manually downloaded the value of MPMediaItemPropertyIsCloudItem is NO, which is correct. I can also access the asset's URL through the MPMediaItemPropertyAssetURL property.
On the other hand, selecting a song that was cached returns YES on MPMediaItemPropertyIsCloudItem and nil on MPMediaItemPropertyAssetURL, making the song virtually useless to me.
Sorry I don't have an actual answer but I don't have enough reputation to simply comment.
Hope my 2 cents help somehow, but it truly seems to me that this issue can only be resolved by Apple in a future update.
A better solution to test if an item comes from iCloud in the didPickMediaItems delegate:
MPMediaItem *selectedItem = [selectedItems objectAtIndex:0];
if (![[selectedItem valueForProperty:MPMediaItemPropertyIsCloudItem] boolValue])
You don't really need to play it, it is more efficient to use the embedded property in the MPMediaItem.
I had this same problem. Although I was unable to hide the items, here's a good workaround that I used to prevent people from being able to select them. Inside didPickMediaItems, you should temporarily load it into an AVPlayerItem and then just check the validity of that item like so:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
MPMediaItem *selectedItem = [[mediaItemCollection items]objectAtIndex:0];
NSURL *tempURL = [selectedItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc]initWithURL:tempURL];
if(playerItem.loadedTimeRanges==NULL)
{
UIAlertView *alert=[[[UIAlertView alloc]initWithTitle:NSLocalizedString(#"Invalid Song Choice",NULL) message:NSLocalizedString(#"Please choose a song that is local to your phone.",NULL) delegate:self cancelButtonTitle:NSLocalizedString(#"Okay",NULL) otherButtonTitles:nil]autorelease];
[alert show];
[playerItem release];
}
else
{
NSLog(#"Your good to go...do whatever you want with the local song");
}
}
It appears to be fixed in iOS 7.
The following code works; iCloud items are not showing:
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.showsCloudItems = NO;

UIImagePickerController Memory Leak

I am seeing a huge memory leak when using UIImagePickerController in my iPhone app. I am using standard code from the apple documents to implement the control:
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePickerController animated:YES];
break;
case 1:
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
break;
default:
break;
}
}
And for the cancel:
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
[picker release];
}
The didFinishPickingMediaWithInfo callback is just as stanard, although I do not even have to pick anything to cause the leak.
Here is what I see in instruments when all I do is open the UIImagePickerController, pick photo library, and press cancel, repeatedly. As you can see the memory keeps growing, and eventually this causes my iPhone app to slow down tremendously.
As you can see I opened the image picker 24 times, and each time it malloc'd 128kb which was never released. Basically 3mb out of my total 6mb is never released.
This memory stays leaked no matter what I do. Even after navigating away from the current controller, is remains the same. I have also implemented the picker control as a singleton with the same results.
Here is what I see when I drill down into those two lines:
Any help here would be greatly appreciated! Again, I do not even have to choose an image. All I do is present the controller, and press cancel.
Update 1
I downloaded and ran apple's example of using the UIIMagePickerController and I see the same leak happening there when running instruments (both in simulator and on the phone).
http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010196
All you have to do is hit the photo library button and hit cancel over and over, you'll see the memory keep growing.
Any ideas?
Update 2
I only see this problem when viewing the photo library. I can choose take photo, and open and close that one over and over, without a leak.
It's a bug in the SDK. File a report with Apple. I have the samme isue. It is also documented here: http://www.cocoabuilder.com/archive/cocoa/285293-iphone-memory-leak-can-explain.html
and that was over a year ago and still no fix.
A few of our apps reuse the same UIImagePickerController due to a leak in 2.x (it makes me feel old...). I was under the impression that the leak was fixed, but I could be wrong.
It's a slightly horrible workaround, but sometimes that's the best you can do.
Try setting the UIImagePickerController.delegate to nil before releasing.
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
picker.delegate = nil;
[picker release];
}
The "Mark Heap" button in Instruments has been, for me, the absolute best way of tracking down these sorts of issues.
This is an OK article on how to use it: http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/
But it will tell you, for sure, which objects are surviving longer than you expect... and, ultimately, what the source of the issue is.
You can also see a complete retain/release trace for each individual object which survived - allowing you to pinpoint where your problem is.
EDIT: I use a UIImagePickerControllers as well, and I can promise it doesn't leak (at lesat for me) the way you're suggesting - so, whatever is going on, it's almost surely fixable.
I used UIImagePickerController and after 40 capture images my application received a DidMemoryWarning message and stop, hidden all my views.
In my application I create 40 objects of
UIImagePickerController( new UIImagePickerController() )
To work correctly I create a unique instance shared to all application and with this all work correctly.
I supusose that control lost memory too, but only one time. My application can capture images from camera correctly:
private static UIImagePickerController picker = new UIImagePickerController();

automatically start FrontCamera and capture image

I want to make a camera application in which i want to start front camera automatically and capture image without user interaction. thanks in advance.
In addition to Robin's answer, add the following statements (before presentModalViewController:) to ensure that if the device has a front camera, that should be opened by default
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]){
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; //skipping this was crashing my app with some ** Assertion failure.
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Please note, if your app is compatible with devices running OS older than 4.0, you will have to put in conditional checks since cameraDevice property is available only in iOS 4.0 and later
The UIImagePickerController is a higher level abstraction to the camera. Have a look at AVFoundation examples to see how to get to the camera more directly.
The documentation for AVFoundation is here.
To do it while still using the picker, have a look at.1317978. Look around for some examples using UIGetScreenImage(). It used to be a private API but I think it is now allowed.
You might also want to look around at some examples concerning custom overlay, like this one.
I dont know how much you know about objective-c or iphone development. so I will tell how to take photos in your iphone app.
First you should get your self aquatinted with UIImagePickerController class
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
here is some examples for the same from apple
http://developer.apple.com/library/ios/samplecode/PhotoLocations/
http://developer.apple.com/library/ios/samplecode/PrintPhoto/
http://developer.apple.com/library/ios/samplecode/PhotoPicker/
http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/
and next here is the code that will help you take the pics if you just place it in your .m file
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
now get started.

iOS4: UIImagePickerController behaving weirdly when presented modally

I'm trying to present a UIImagePickerController from a UITableViewController subclass using the following code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if(library)
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
If I create a brand new project and throw this code in, it works absolutely fine. However, in this project, for some reason, the UIImagePickerController's view appears as a blank white screen if I try to show the Photo Library, or shows the camera view but with no camera controls if I try to show the Camera.
Is there anything in a UITableViewController subclass that would be causing this? I get complaints about two-stage animations as well, but from what I've been able to find, this is an issue with Apple's code.
For some reason, changing the PRODUCT_NAME in the Info.plist (something which I was going to do anyway but hadn't gotten around to until just now) fixed this issue. I have absolutely no idea why, but I'm going to assume it was some obscure bug in the iPhone SDK.