Check Photo gallery is accessible or not iphone - iphone

I am accessing the photo gallery using below code :
UIImagePickerController* picker = [UIImagePickerController new];
picker.sourceType = type;
picker.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:type];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
So I user open Gallery for first time then application is display popup like this :
If user select the OK then its work fine. But if user select the Don't Allow then photo gallery is not able to access from application. My question is if user open Photo Gallery then how to check whether photo gallery is accessible or not.
If user is not allow then application is display the screen like this :
But is there any way to check Accessibility before opening the window.
Thanks,

You can check your access ability using ALAuthorizationStatusAuthorized.
Check authorization status of the app.
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//THen code here ,,,,
}

you might looking for this solution in failure block you can show alert to user that then can give access by go to settings....

Related

iOS 6 Social framework not going to settings or no alert

I'm trying to implement the new social framework in iOS6, and have it working, except for 2 weird problems. If I've enabled the services I'm interested in (say... FaceBook), then it works fine. However, if the accounts are deleted from the settings panel (let's say FaceBook, to be consistent), then I get differing, and frustrating behaviors in the simulator and the device.
Here's the relevant code in my view controller:
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
//check to see if facebook account exists
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
}
And here's the weird behavior when firing off the above method:
In the simulator (version 6.0 (358.4) I get the dialog informing me that I haven't set up any faceBook accounts with "Settings" and "Cancel" buttons. Hitting "Settings" just dismisses the dialog, but doesn't take me to the settings panel.
On my iPhone 4s running 6.01, hitting the button that triggers the method results in... nothing. In other words, I get no dialog informing me that I have to set up a FaceBook account.
Thanks in advance for your help.
OK... Here's the fix:
Here's my new implementation, based on user1734802's helpful comment.
//Method for FaceBook
- (IBAction)doFacebook:(id)sender{
// Create the view controller defined in the .h file
fb=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// make the default string
NSString *FBString= [NSString
stringWithFormat:#"%#\r via #GibberishGenerator", gibText.text];
[fb setInitialText:FBString];
// show the controller
[self presentViewController:fb animated:YES completion:nil];
}
At some point I expect
[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
to actually work correctly (triggering the automatic dialog, and taking you to settings), so I actually just commented it out in my code.
I had the same problem, i fixed it by removing the If statement:
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
Then the view will display although there is no Facebook/Twitter account configured in the settings.
And the "No Facebook/Twitter accounts" alertView showed! And I was able to hit the "Settings" button on the alert, and it directed me to the settings (Configure Facebook/Twitter account in the settings)
This is the code I used, and it works perfectly for me:
- (IBAction)bTwitter:(id)sender {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[mySLComposerSheet setInitialText:#""];
[mySLComposerSheet addImage:[UIImage imageNamed:#""]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}

UIDocumentInteractionController no longer works in iOS6

I have an app that shares with instagram built for iOS5 and now in iOS6, sharing no longer works although canOpenURL returns true and code executes. The images are saved to the documents folder of the application with a .igo extension. This is passed to instagram with com.instagram.exclusivegram.
The code is below, it enters the if statement and displays "here in" but does not open the Share With dialog like it used to at the bottom of the screen.
NSLog(#"%#", _imgToUpload);
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
uidController = [[UIDocumentInteractionController alloc] init];
//imageToUpload is a file path with .igo file extension
uidController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:_imgToUpload]];
uidController.UTI = #"com.instagram.exclusivegram";
uidController.delegate = self;
CGRect navRect = self.view.frame;
[uidController presentOpenInMenuFromRect:navRect inView:[UIApplication sharedApplication].keyWindow animated:YES];
NSLog(#"here in");
}
_imgToUpload is providing the correct filepath as well.
Thank you,
Nick
Just did some testing and found a solution. Do not present in the keyWindow.
[uidController presentOpenInMenuFromRect:navRect inView:self.view animated:YES];
I have tested this and it will fix the problem.
Another reason for the uidocumentinteraction controller not working in iOS6 is that the new action sheet/launch panel (it shows apps available to open the doc) is now used. My app which worked fine launching iBooks with iOS5 failed because I launched from viewDidLoad which was now too early and I got an error on the current view controller 'whose view is not in the window hierarchy' so I changed my code to performselector after delay of 1 second. The app now calls iBooks via the new panel.

get the list of application through UIDocumentInteractionController

I am using UIDocumentInteractionController to open the list of available pdf application in my device when i click on button but now i want to display setting table which will show the list of all the application and user will be directlly redirect to that applcation next time without displaying the actionsheet or any option
my cade is as below:
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController retain];
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
how can i do that?
You don't, it's not possible using the official SDK to:
Get a list of apps that open a certain file
Open a file with a certain app
One thing you can do is open a URL and the system will decide which app to open.

How to record video in iPhone using Objective-C?

I have a map application in which there is a button named video. If a user clicks on the video button he can record video at any location he like and simultaneously play the video.
How can I do this? My code is as follows:
-(IBAction)video:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){ NSLog(#"device not supported"); return; } picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo]; picker.videoQuality = UIImagePickerControllerQualityTypeHigh; [self presentModalViewController:picker animated:YES]; }
From Apple Programming guides
Starting in iPhone OS 3.0, you can
record video, with included audio, on
supported devices. To display the
video recording interface, create and
push a UIImagePickerController object,
just as for displaying the
still-camera interface.
To record video, you must first check that the camera source type
(UIImagePickerControllerSourceTypeCamera)
is available and that the movie media
type (kUTTypeMovie) is available for
the camera. Depending on the media
types you assign to the mediaTypes
property, the picker can directly
display the still camera or the video
camera, or a selection interface that
lets the user choose.
Using the UIImagePickerControllerDelegate
protocol, register as a delegate of
the image picker. Your delegate object
receives a completed video recording
by way of the
imagePickerController:didFinishPickingMediaWithInfo:
method.
On supported devices, you can also pick previously-recorded videos from a
user’s photo library.
For more information on using the image picker class, see
UIImagePickerController Class
Reference. For information on trimming
recorded videos, see
UIVideoEditorController Class
Reference and
UIVideoEditorControllerDelegate
Protocol Reference.
Once you have the video in your UIImagePickerController delegate you can then save it to your app's documents directory using standard file operations.

Skip UIImagePickerController Preview View?

I'm using UIImagePickerController to allow my user to select a video from the asset library.
When the UIImagePickerController is initially displayed, it shows thumbnails for the various movies that have been recorded.
Once the user selects a movie, it displays a "preview" view which allows them to playback and potentially edit the selected movie.
Is there any way to avoid displaying this view and instead return the movie that was selected on the thumbnail screen?
Here is the code I'm using:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
I haven't tested this myself, though I'll be attempting this in my own application shortly. If you take a look at the UIImagePickerController showsCameraControls documentation, it alludes to the fact that if you eliminate the camera controls you can take as many photos as you want.
So theoretically if you set showsCameraControls to NO, and assign your own cameraOverlayView UIView to let the user take a photo, you can dismiss the image picker without the preview view from showing.
Perhaps that helps. You could listen with the NSNotificationCenter on #"_UIImagePickerControllerUserDidCaptureItem". If the user select the item, you could dismiss the imagePicker and do your thumbnail stuff.
I had a similar issue, to remove an overlay on the preview view and could solve it with this approach.