iOS6 problems to Tweet in UITabBarController using image taken from UIImagePickerController - xcode

After picking image from UIImagePickerController I want to Tweet it but there is error!
Warning: Attempt to present <SLTwitterComposeViewController: 0x210d84b0> on <UITabBarController: 0x1fd67650> while a presentation is in progress!
P.S
This is tabbar application (4 tabbars)
All code:
-(void)useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}
- (IBAction)buttonTweet:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:[NSString stringWithFormat:#"#this is tweet text"]];
[composeController addImage:sender];
[composeController addURL: [NSURL URLWithString:#"http://www.abc.com"]];
[self presentViewController:composeController animated:YES completion:nil];
}

You are presenting a new view controller while the old one is still disappearing. You can present the new one upon completion of the other animation by doing it like this:
[self dismissViewControllerAnimated:YES completion:^{
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}];

Related

Posting via SLComposeViewController on facebook and twitter in IOS-8

I have tried to post on facebook and twitter using SLComposeViewController. my code is
-(void)postToFacebookWithObject:(id)object FromController:(UIViewController*)vc {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
DLog(#"Cancelled");
}
else
{
DLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller removeAllImages];
[controller removeAllURLs];
NSMutableDictionary *item = (NSMutableDictionary *)object;
[controller setInitialText:[item objectForKey:#"DealTitle"]];
if([item objectForKey:#"DealImage"])
[controller addImage:[item objectForKey:#"DealImage"]];
if([item objectForKey:#"url"])
[controller addURL:[NSURL URLWithString:[item objectForKey:#"url"]]];
[vc presentViewController:controller animated:YES completion:Nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:LocStr(#"NO_FACEBOOK_ACCOUNT_CONFIGURED") delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
DLog(#"UnAvailable");
}
}
this working fine in ios 7 but in ios 8 this sheet coming behind my view which i have added on window. How i can fix this?
I have solve this issue by adding my view on navigationcontroller.view not on window.
I have resolved through open present-view controller in navigation-bar.it may help you.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:shareFrom];
[controller addImage:self.photoImageView.image];
[controller addURL:[NSURL URLWithString:dayCareWebsite]];
dispatch_async(dispatch_get_main_queue(), ^ {
[self.navigationController presentViewController:controller animated:YES completion:nil];
});
UINavigationController *forShare = [[UINavigationController alloc] initWithRootViewController:vc];
[forShare setNavigationBarHidden:YES];
[self presentViewController:forShare animated:NO completion:nil];
if animated:YES it doesn't works
if animated:NO it works for me

ALAssetsLibrary writeImageToSavedPhotosAlbum block the program in iOS8

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary* meta = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.locationManager.location){
NSDictionary* locationMeta = [self gpsDictionaryForLocation:self.locationManager.location];
[meta setObject:locationMeta forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:img.CGImage metadata:meta completionBlock:^(NSURL* assetUrl, NSError* error){
//.......
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
This code worked fine in iOS7. After I upgraded my device to iOS8, the program was blocked and imagePickerView didn't dismiss.
Is this a bug in iOS8? Anyone can help me?

Take Photos from camera and library

hi in my app i am able to take a photo or select a photo from library and display it in a imageview
but my question is how can i add a second image view and display a image in that
here is my code
- (IBAction)TakePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)ChoosePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageView setImage:image]; // "myImageView" name of any UImageView.
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
What I think from your question is you are going to select two image one bye one.
Either from camera or from photo library.
Try this one:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(ImageView.image == Nil)
{
[ImageView setImage:image];
}
else if(ImageView2.image == Nil)
{
[ImageView2 setImage:image];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}

How to make actionsheet go to another view? Xcode, small issue,,,

I am trying to make an actionsheet for another button but I get two errors: "No visible #interface for 'UIstoryboard' declares the selector 'InitiateViewControll:' and, "No visible #interface for SWViewController' declares the selector 'presentViewController:animated:' I was giving this code so is there any names that I need to name in this to make this code costomized for my code? I am trying to learn i am a noob sorry :( here is the code I have so far:
- (IBAction)OpenActionSheetButton:(id)sender {
UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:#"There is no going back, are you sure???" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"Continue" otherButtonTitles:nil, nil];
[actionsheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
UIViewController *controller = [self.storyboard instantiateViewControll:#"storyboardViewName"];
//Push
[self.navigationController pushViewController:controller animated:YES];
//Modal
[self presentViewController:controller animated:YES];
}
}
Please help guys?
Try out this code..And SWViewController must have a Navigation Controller
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"storyboardViewIdentifier"];
//storyboardViewIdentifier is the ViewController identifier you specify in the storyboard
//PUSH
[self.navigationController pushViewController:controller animated:YES];
//Modal
[self presentViewController:controller animated:YES completion:Nil];
}
}
Try this. It works for me:
if(buttonIndex == 0)
{
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
Paypal_ViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"Paypal_ViewController"];
[self presentViewController:vc animated:YES completion:nil];
}

UIActivityViewController

I have a problem with the UIActivityViewController on iPad
Here is my Code:
NSString* someText = #"Hi, I am using the official iEveryThing Tech app #iEveryTech";
NSString* Website = [NSURL URLWithString:#"https://itunes.apple.com/us/app/ieverytech/id578148847?l=de&ls=1&mt=8"];
NSArray* dataToShare = #[someText,Website];
Class activityViewController = NSClassFromString(#"UIActivityViewController");
if(activityViewController) {
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];}
}
On iPhone the Mail composer View will disappear after sending the mail but not the Composer on the iPad here is my Composer:
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"error"
message:[NSString stringWithFormat:#"error %#", [error description]]
delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
}
The activityViewController use a native method for send mail don't need use mailComposeController, like this
NSMutableArray *items = [NSMutableArray new];
[items addObject:#"text for share"];
[items addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:self.imagePath]]];
NSArray *activityItems = [NSArray arrayWithArray:items];
self.activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:whatsapp,instagram, nil]];
self.activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint,UIActivityTypeAirDrop,UIActivityTypeCopyToPasteboard];
[self presentViewController:self.activityVC animated:YES completion:nil];
First thing, when using the activityViewController, your class is not the delegate for the mail composer and the code will not be called. This is all handled internally in the activityViewController.
As for your view not being dismissed, implement the complete block call for the activityViewController. In the block be sure to dismiss the view controller.

Resources