give ios simulator permission to access photo albums [duplicate] - ios

This question already has answers here:
iOS stopped asking user for Photo Library Permission
(6 answers)
Closed 8 years ago.
I've an iphone app where the user is able to upload photos. During test on ios simulator, everytime I click the "upload image" button, the simulator pops up an alert that says I should give the app permission to access photo albums.
The problem is that the simulator never asked me before if I want to give it access or not. And when I go to privacy settings on the simulator -> photos, I do no see the app to toggle it ON!
I tried resetting content & settings of the simulator, but that didn't solve the problem.
I'm using xCode 5.0.2
Simulator 7.0 iOS 6.1 simulator component

did you check Settings->Privacy->Photos? you should allow your app have full access here.

add following code to somewhere
UIImagePickerController* picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:Nil];
remember to add this function to handle picked image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
try this then to see what happened on your machine.

I found the problem
There is code
if (status != ALAuthorizationStatusAuthorized) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Please give the app access to photo album" delegate:nil cancelButtonTitle:#"Close" otherButtonTitles:nil, nil];
[alert show]; }
I changed:
if (status != ALAuthorizationStatusAuthorized) {
to
if (status == ALAuthorizationStatusDenied) {
Then it worked and asked me for permission, accepted it, and everything is ok now
Thanks everyone

Related

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.

Cannot Launch an app from within another (iPhone)

I have followed exactly the same tutorial Launch an app from within another (iPhone) but the code is only executing the else part and showing alert, So I am unable to open the second app. You can see the steps I have followed in the link above.
Let's assume that we have two apps called FirstApp and SecondApp. When we open the FirstApp, we want to be able to open the SecondApp by clicking a button. The solution to do this is:
In SecondApp
Go to the plist file of SecondApp and you need to add a URL Schemes with a string iOSDevTips(of course you can write another string.it's up to you).
2 . In FirstApp
Create a button with the below action:
- (void)buttonPressed:(UIButton *)button
{
NSString *customURL = #"iOSDevTips://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"URL error"
message:[NSString stringWithFormat:#"No custom URL defined for %#", customURL]
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
Add the custom Url in info.plist
1st image - In Your App which you are opening
2nd Image - In Your App which from you are opening
For full explanation and code visit my blog here

Is there any way to detect if a user actually pressed the Twitter/Facebook post button in app?

I am trying to give "bonus points" for users who either tweet my advertisement message or post my advertisement message on Facebook. How can I detect if...
1) The user actually pressed the post button (this way I can give them the bonus points in app)?
2) The user did not change any text in the message box (my advertisement)?
On a side note, is it possible to make the message box for these un-editable? Here is my code to actually present the message to post each:
- (IBAction)tweetButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"My advertisement message goes here."];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Twitter Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Twitter through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (IBAction)facebookPostButtonPressed:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My advertisement message goes here."];
[self presentViewController:controller animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Facebook Connection Failed"
message:#"Make sure your device has an internet connection and you are connected to Facebook through your iPhone settings."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
You can use compliton hander to know if he press the post button, however you can't know what the content of the post.
If you realy want to you need to implement facebook yourself than you can even check the privecy of the post.
I say this because when a app ask me to post I always do it as "Private" so no one see but I still get the "Bonus".
Apple Docs
Possible values for the result parameter of the completionHandler property.
Declaration
OBJECTIVE-C
typedef NS_ENUM (NSInteger,
SLComposeViewControllerResult ) {
SLComposeViewControllerResultCancelled,
SLComposeViewControllerResultDone
};
Constants
SLComposeViewControllerResultCancelled
The view controller is dismissed without sending the post. For example, the user selects Cancel or the account is not available.
Available in iOS 6.0 and later.
SLComposeViewControllerResultDone
The view controller is dismissed and the message is being sent in the background. This occurs when the user selects Done.
Available in iOS 6.0 and later.
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Reference/SLComposeViewController_Class/#//apple_ref/c/tdef/SLComposeViewControllerResult

Orientation issue in Landscape mode while opening camera in iOS 7 in iPhone

I am having an app which is only in Landscape Mode. In my app I am opening the Camera from one of my views. It is working well for my iPad but on iPhone it crashes. It is working well in iOS 6 but the app crashes for iOS 7 and only for iPhone.
Below is my code.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc=[[UIImagePickerController alloc] init ];
ipc.delegate=self;
ipc.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:ipc animated:YES completion:nil];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Desc" message:#"Camera capture is not supported in this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
How to solve this issue?
It crashes when I select to capture from camera. It doesn't crash from the above code but after that it crashes with below error.
I am getting this error:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
And my app crashes.
My orientation code on this view.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ;
}
I am also getting same problem previously. I followed the steps. Please try this and let me know if your facing same problem.
check mark
Step 1:
check in appdelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
step 2: In your view controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
Step 3: your view controller
-(IBAction)TakePhoto:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];//add to view as per requirement
}
else
{
UIAlertView *noCam = [[UIAlertView alloc] initWithTitle:#"Notification" message:#"There is No Camera Fecility" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[noCam show];
}
}
Does the crash occur on launching the UIImagePickerController or after taking an image with the camera? I tried out your code on an iPod running iOS7 and it works fine. The issue could be somewhere else. I've seen crashes happening with the UIImagePickerController due to memory usage so that could be something for you to check. Also while we're at it, presentModalViewController:animated: is deprecated since iOS6.0. You need to use presentViewController:animated:completion: instead. Also seeing the release statement for your UIAlertView, it looks like you're not using ARC so memory usage is definitely something I would look into. Hope this helps.EDIT: From the UIImagePickerController documentationImportant: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
Try this code, it works on my old app.
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
May be you want to check this: GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation
I found my solution from the link iOS7 iPad Landscape only app, using UIImagePickerController.
It worked for me like a charm.
Hope it help someone else also.
Thanks for your help people.
I had inherited the UIImagePickerController, and override the tow methods to supported landscape (or you can make a category):
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate
{
return YES;
}
And add the Portrait (bottom home button), Landscape (left home button), Landscape (right home button) in Supported interface orientations(iPad).
Here, must add the Portrait (bottom home button) value, because the UIImagePickerController just supports portrait mode only, so we need to add the portrait mode, otherwise it will raise an exception.

Runtime error when using MPMediaPickerController in iOS Simulator

The following happens when I try to run an app using the MPMediaPickerController on the iOS Simulator.
2012-05-28 22:26:42.416 My App[48426:11f03] Could not load source: 3
2012-05-28 22:26:42.418 My App[48426:11f03] *** Assertion failure in -[MPMediaPickerController loadView], /SourceCache/MediaPlayer_Sim/MobileMusicPlayer-1391.72/SDK/MPMediaPickerController.m:86
2012-05-28 22:26:42.419 My App[48426:11f03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to load iPodUI.framework'
Is this some problem in my App/Xcode/iOS Simulator, or does the iOS Simulator simply not support the MPMediaPickerController? If not, any alternatives, besides running it on a physical device?
MPMediaPickerController does not work in the Simulator. Apple notes this in the "iPod Library Access Programming Guide" under "Hello Music Player". The note says:
Note: To follow these steps you’ll need a provisioned device because
the Simulator has no access to a device’s iPod library.
To prevent the assertion you can always check if you can access the do this in your code (code bellow uses ARC and iOS SDK 5.0).
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[picker setDelegate:self];
[picker setAllowsPickingMultipleItems:YES];
[picker setPrompt:NSLocalizedString(#"Add songs to play","Prompt in media item picker")];
#try {
[picker loadView]; // Will throw an exception in iOS simulator
[self presentViewController:picker animated:YES completion:nil];
}
#catch (NSException *exception) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Oops!",#"Error title")
message:NSLocalizedString(#"The music library is not available.",#"Error message when MPMediaPickerController fails to load")
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
}
Also (if using storyboard) you can try it:
- (IBAction)showPicker:(id)sender
{
#if TARGET_IPHONE_SIMULATOR
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"playerTest"
message:#"Media picker didn't work in simulator, please run this app on device"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
#else
[self performSegueWithIdentifier:#"ShowPickerViewSegue" sender:self];
#endif
}
MPMediaPickerController now works in the iOS Simulator without any additional code changes (at least as of iOS 8, possibly earlier). Here is a project that can demonstrate it: GVMusicPlayerController.
You will have to prepare the music library in the Simulator by copying the necessary files from an actual device, most importantly the MediaLibrary.sqlitedb database files. If you want to play the files and view artwork, you'll also have to copy the iTunes_Control/Music, Purchases and Artwork folders (found in /var/mobile/Media/). See this question for further details: Can i access iPod Library on simulator?.

Resources