Error presentViewController - view controllers adding - objective c - ios

I have a problem and can't know the reason or solution
I have AddDelegate and another ViewController, in this ViewController I add FBFriendPickerViewController, and ViewController will be added to AppDelegate ..
I add ViewController to AppDelegate like this: ( this ViewController is SocialSharing class )
if( socialSharing == nil )
socialSharing = [[SocialSharing alloc] init];
[_window.rootViewController.view addSubview:socialSharing.view];
And add FBFriendPickerViewController in ViewController(SocialSharing) like this:
-(void)shareOnFaceBook:(NSNotification *) notification
{
if( shareOnUserOrFriendWallBtnIndex == 0 )
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSURL *candidateURL = [NSURL URLWithString:contentDataToShare];
if (candidateURL && candidateURL.scheme && candidateURL.host) {
[facebookSheet setInitialText:#"See this link .."];
[facebookSheet addURL:candidateURL];
}
else // Event ***
{
[facebookSheet setInitialText:[NSString stringWithFormat:#"%#%#%#",[[appDelegate.extrasOverlayView.markerData.btnsArr objectAtIndex:0] objectForKey:#"markerName"],#" .. \n", contentDataToShare]];
[facebookSheet addURL:[NSURL URLWithString:lastVideoLink]];
}
//Brings up the little share card with the test we have pre defind.
[appDelegate.window.rootViewController presentViewController:facebookSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Facebook account setup and your device is using iOS." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
else if( shareOnUserOrFriendWallBtnIndex == 1 )// post on friend's wall
{
if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]] )
{
NSLog(#"Facebook is inastalled on this device.");
if( friendPickerController == nil )
{
friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.delegate = self;
if( !( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) )
friendPickerController.title = #"Select Friends";
}
[friendPickerController loadData];
// Present view controller modally
[self presentViewController:friendPickerController animated:YES completion:nil];
}
else{
NSLog(#"This device has no Facebook app.");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't invite friends, Facebook app isn't installed, please install it and retry again." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
}
and dismiss friendPickerController from SocialSharing like:
- (void)facebookViewControllerCancelWasPressed:(id)sender
{
NSLog(#"Friend selection cancelled.");
[self dismissViewControllerAnimated:YES completion:nil];
}
I used:
[friendPickerController dismissModalViewControllerAnimated:YES];
OR //[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:Nil];
OR //[self dismissModalViewControllerAnimated:YES];
It works good for only first time, once, friendPickerController appears and dismiss when close, BUT when call to open again, I have this error:
"Thread 1: signal SIGBRT"
FOR the line of :
[self presentViewController:friendPickerController animated:YES completion:nil];
Note: when I add friendPickerController on AppDelegate directly (in class of AppDelegate) without another class (here is SocialSharing ViewController), it works great ..
I'm working on IOS 7, and Facebook SDK 3.13..
So, What is the problem, How can I solve it ?
Thank you

What I did to solve my problem, I create friendPickerController in NORMAL CLASS , NOT ViewController, and add it on AppDelegate
[appDelegate.window.rootViewController presentViewController:friendPickerController animated:YES completion:nil];
and dismiss by:
[appDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
And call this Class like:
if( socialSharing == nil )
{
socialSharing = [[SocialSharingClass alloc] init];
[socialSharing initSocialSharing];
}
Still, I don't know the problem, but that solved it. May that help anyone.

Related

Cannot Close Game Center Leaderboards Page

I can load up leaderboards with no problem. But I can't get it to close when the "Done" button is clicked.
How I'm opening it:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
How I'm closing it:
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
NSLog(#"test");
[self dismissViewControllerAnimated:YES completion:nil];
}
EDIT:
The method isn't running at all; so "test" doesn't even get printed.
And I added <GKGameCenterControllerDelegate> to my ViewController's protocol.
Try this instead:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
leaderboardController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
And:
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}

UIImagePickerController not presenting in iOS 8

Is anyone else having an issue with UIImagePickerController in iOS 8? The method below works perfectly well in iOS 7 on an iPad, but I get the following error when I run this in XCode 6 (Beta 3 or 4) when I try to present the picker (last line). If it matters, the selection of the sourceType is coming from an alertView that is presented in the same place.
Warning: Attempt to present <UIImagePickerController: 0x7c0ae400> on <CAGUCreateContactViewController: 0x7bf61a00> which is already presenting (null)
Method to open imagePicker.
- (void)openPhotoPicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.sourceType = sourceType;
imagePickerController.mediaTypes = #[(NSString *)kUTTypeImage];
imagePickerController.delegate = self;
self.imagePickerController = imagePickerController;
if (sourceType == UIImagePickerControllerSourceTypeCamera) {
[self presentViewController:self.imagePickerController animated:YES completion:nil];
} else {
if (self.popoverVC) {
[self.popoverVC dismissPopoverAnimated:YES];
self.popoverVC = nil;
}
self.popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.popoverVC presentPopoverFromRect:self.nameAndPicCell.picture.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
}
}
I think this is because in iOS 8, alert views and action sheets are actually presented view controllers (UIAlertController). So, if you're presenting a new view controller in response to an action from the UIAlertView, it's being presented while the UIAlertController is being dismissed. I worked around this by delaying the presentation of the UIImagePickerController until the next iteration of the runloop, by doing this:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self openPhotoPicker:sourceType];
}];
However, the proper way to fix this is to use the new UIAlertController API on iOS 8 (i.e. use if ([UIAlertController class]) ... to test for it). This is just a workaround if you can't use the new API yet.
I agree with Ben Lings issue detection. I would suggest a simpler solution in case when using UIActionSheet. I simply moved my code that reacts on Action Sheet selection from:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
// my code
}
into:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
{
// my code
}
This way app is guarantied that code will be executed AFTER UIActionSheet animation finishes.
Since UIAlertView has similar delegate method:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
{
// my code
}
I suppose that similar solution may apply.
Here is a solution that worked for me
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:cameraUI animated:NO completion:nil];
}];
}
else{
[controller presentViewController:cameraUI animated:NO completion:nil];
}
Remember to alloc cameraUI
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
Build and Go!
I was facing the same problem in iOS 8.
Then I saw the change log of the latest update to iOS i.e. 8.0.2 on the device.
It is mentioned in this update that_
"Fixes an issue that prevented some apps from accessing photos from Photo Library"
So test your app using XCode 6 on device with iOS 8.0.2 version it will work fine
Don't test it on iOS 8.0 simulator.
This helped me, hope the same for you.
UIImagePickerController *imagePickerController= [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
// image picker needs a delegate so we can respond to its messages
[imagePickerController setDelegate:self];
self.shouldCallViewWillAppear = NO;
if(IS_IOS8)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
// Place image picker on the screen
[self presentViewController:imagePickerController animated:YES completion:nil];
}];
}
else
{
[self presentViewController:imagePickerController animated:YES completion:nil];
}
You can dismiss the presented view controller (if any) by using
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
This worked for me.
All you need to do is dismiss already presented ViewController:
if (self.presentedViewController) {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
[self openPhotoPicker:sourceType];
If it still produces error, put openPhotoPicker: to completion handler
I simply did this:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,
(unsigned long)NULL), ^(void) {
[self retractActivePopover];
dispatch_async(dispatch_get_main_queue(), ^ {
_activePopover=imagePickerPopover;
UIBarButtonItem *callingButton = (UIBarButtonItem*) sender;
[imagePickerPopover presentPopoverFromBarButtonItem:callingButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
});
});
On iOS 8 you should use the new API:
if (SYSTEM_VERSION_IOS_8) {
self.imagePickerController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = self.imagePickerController.popoverPresentationController;
popPC.barButtonItem = self.popoverItem;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:self.imagePickerController animated:YES completion:nil]
}
I recommend you watch the 2014 WWDC session 228 a look in side presentation controllers
I went through a lot of pain coming up with a solution which works on both iPad and iPhone, this is the final code which some of it comes from comments of other people:
the code has some bugs but it's a very good place to start :)
definitions :
__weak IBOutlet UIButton *attachButton;
UIImage *image;
button's action :
- (IBAction)doAttach:(id)sender {
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#"Select image from" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"From library",#"From camera", nil] ;
[action showInView:self.view];
}
#pragma mark - ActionSheet delegates
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if( buttonIndex == 1 ) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
NSLog(#"%#", #"You have camera access");
}
else if(authStatus == AVAuthorizationStatusDenied)
{
NSLog(#"%#", #"Denied camera access");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", AVMediaTypeVideo);
} else {
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no camera access“
message: #“if you need to use camera in this application go to settings -> appName -> and turn on camera.”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(#"Not granted access to %#", AVMediaTypeVideo);
return ;
}
}];
}
else if(authStatus == AVAuthorizationStatusRestricted)
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no camera access“
message: #“if you need to use camera in this application go to settings -> appName -> and turn on camera.”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(#"%#", #"Restricted, normally won't happen");
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
NSLog(#"%#", #"Camera access not determined. Ask for permission.");
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", AVMediaTypeVideo);
} else {
NSLog(#"Not granted access to %#", AVMediaTypeVideo);
return ;
}
}];
}
else
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“No camera access“
message: #“error accusing camera”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
return;
//NSLog(#"%#", #"Camera access unknown error.");
}
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *pickerView =[[UIImagePickerController alloc]init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
pickerView.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[ self.presentedViewController dismissViewControllerAnimated:YES completion:nil ];
pickerView.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = pickerView.popoverPresentationController;
popPC.sourceView = attachButton;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:pickerView animated:YES completion:nil];
} else {
[self presentModalViewController:pickerView animated:YES ];
}
}
}else if( buttonIndex == 0 ) {
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
switch (status) {
case ALAuthorizationStatusRestricted:
case ALAuthorizationStatusDenied:
{
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:#“no access to library”
message: #“if you wish to access photos in this app go to settings -> appName-> and turn on photos .”
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#“ok” style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
}
break;
default:
{
UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
pickerView.allowsEditing = YES;
pickerView.delegate = self;
[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[ self.presentedViewController dismissViewControllerAnimated:YES completion:nil ];
pickerView.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popup = pickerView.popoverPresentationController;
popup.sourceView = attachButton;
popup.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:pickerView animated:YES completion:nil];
} else {
[self presentModalViewController:pickerView animated:YES ];
}
}
break;
}
}
}
#pragma mark - PickerDelegates
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[self dismissModalViewControllerAnimated:true];
UIImage * img = [info valueForKey:UIImagePickerControllerEditedImage];
image = img;
}
performSelector:withObject:afterDelay solved my problem.
also didDismissWithButtonIndex do the trick.
Max
Here's a Xamarin solution. What worked for me was to add my actions to a Dismissed event handler.
this.btnPhoto.TouchUpInside += (sender, e) =>
{
actionSheet = new UIActionSheet ("Add Photo");
actionSheet.AddButton ("Take Photo");
actionSheet.AddButton ("Select from Library");
actionSheet.AddButton ("Cancel");
actionSheet.DestructiveButtonIndex = -1; // red
actionSheet.CancelButtonIndex = 3; // black
actionSheet.Clicked += delegate(object a, UIButtonEventArgs b)
{
actionSheet.Dismissed += (object aSender, UIButtonEventArgs dismissArgs) =>
{
switch (dismissArgs.ButtonIndex)
{
case 0:
showCamera ();
break;
case 1:
showPhotoLibrary ();
break;
}
};
};
actionSheet.ShowInView (view);
};

Game Center In SpriteKit Not Dismissing Leader Board

After a lot of searching on here I finally found a way for Game Center to display in SpriteKit but now I can't get the leaderboardViewControllerDidFinish method to call. I use this code in a different app and it works fine but for some reason with the code being modified for SpriteKit its just not working. Thank you in advance!
Here is a sample of my code:
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *leaderboardViewController = [[GKGameCenterViewController alloc] init];
if (leaderboardViewController != NULL)
{
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: leaderboardViewController animated: YES completion:nil];
}
}
}
}
- (void)leaderboardViewControllerDidFinish:(GKGameCenterViewController *)viewController {
NSLog(#"in leaderboardControllerDidFinish");
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
To answer my own question...
I just took the code straight from Apple
- (void)showGameCenterButtonPressed:(id)sender {
{
if ([GKLocalPlayer localPlayer].authenticated == NO) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"You must enable Game Center!"
message:#"Sign in through the Game Center app to enable all features"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
} else {
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: gameCenterController animated: YES completion:nil];
}
}
}
}
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController {
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}

UIImagePickerController camera type returning black image

I am struggling with UIImagePickerController as when i open camera and take image it show black screen in IOS 7 as this is working fine in ios 6, i have tried some other links what says but its not working, please help me with this...
and i am getting this error too
<Error>: CGAffineTransformInvert: singular matrix.
and now i got something ..
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
when i just click on take image button
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
dispatch_async(dispatch_get_main_queue(), ^{
if (buttonIndex == 0) {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
// This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
if(authStatus == AVAuthorizationStatusRestricted){
NSLog(#"Restricted");
}
// The user has explicitly denied permission for media capture.
else if(authStatus == AVAuthorizationStatusDenied){
NSLog(#"Denied");
}
// The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
else if(authStatus == AVAuthorizationStatusAuthorized){
NSLog(#"Authorized");
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:imagePickerCamera animated:YES completion:^{}];
});
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
// Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
else if(authStatus == AVAuthorizationStatusNotDetermined){
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted){
NSLog(#"Granted access to %#", mediaType);
}
else {
NSLog(#"Not granted access to %#", mediaType);
}
}];
}
else {
NSLog(#"Unknown authorization status");
}
}
else {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
dispatch_async(dispatch_get_main_queue(), ^{
UIImagePickerController *imagePickerCamera =[[UIImagePickerController alloc] init];
imagePickerCamera.delegate = self;
imagePickerCamera.mediaTypes = #[(NSString *) kUTTypeImage];
imagePickerCamera.allowsEditing = YES;
imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePickerCamera animated:YES completion:nil];
});
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
} else if (buttonIndex == 1) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *imagePickerAlbum =[[UIImagePickerController alloc] init];
imagePickerAlbum.delegate = self;
imagePickerAlbum.mediaTypes = #[(NSString *) kUTTypeImage];
imagePickerAlbum.allowsEditing = YES;
imagePickerAlbum.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerAlbum animated:YES completion:nil];
} else {
NSString *errorString = [NSString stringWithFormat:#"This device does not support this feature."];
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
}
});
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
_upLoadimage = info[UIImagePickerControllerEditedImage];
}
I had the same problem with camera. My screen to modify or editing camera image was appearing black. The log showed me same error (CGAffineTransformInvert xx ). I did a lot of checks to determine or know where is the error.
In my application I use the component SVProgessHUD to show alerts and messages. Commenting lines with this use corrects the problem. I have updated to the last version of the component (1.0) and the error CGAffineTransformInvert disappears.

IOS twitter app to add image

I'm creating an application that has integration with Twitter .. and wanted to know what have to do to create a button to add an image of the device in the tweet.and also wanted to know which framework to use it and also where the code
You can just use the twitter framework, it's included since iOS 5
And the code i use:
- (IBAction)twitter:(id)sender {
if([TWTweetComposeViewController canSendTweet])
{
NSLog(#"Ready to Tweet.");
TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer setInitialText:[NSString stringWithFormat:#"My message"]];
[tweetComposer addImage:[UIImage imageNamed:#"114x114"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://myPage"]];
tweetComposer.completionHandler = ^(TWTweetComposeViewControllerResult result){
if(result == TWTweetComposeViewControllerResultDone){
NSLog(#"Tweeted.");
} else if(result == TWTweetComposeViewControllerResultCancelled) {
NSLog(#"Cancelled.");
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
};
[self presentModalViewController:tweetComposer animated:YES];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops"
message:#"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}

Resources