Posting via SLComposeViewController on facebook and twitter in IOS-8 - ios8

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

Related

Message is not post on FB

SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:kShareViaFacebookMessage];
[controller addURL: [NSURL URLWithString:kShareViaFacebookURL]];
[self presentViewController:controller animated:YES completion:Nil];
what is the issue in this code? why it is not displaying message on post?

UIAlertController Warning Message

I am using the below code for UIAlertController in my project.
if([[[UIDevice currentDevice] systemVersion]floatValue] >= 8.0){
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:#"Input Error"
message:#"Please enter a valid email."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction
actionWithTitle:#"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Input Error"
message:#"Please enter a valid email"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alertView show];
}
I am getting the below waring message:
Warning: Attempt to present <UIAlertController: 0x7f8da58df1f0> on <MBComplaintsViewController: 0x7f8da36454d0> which is already presenting (null)
Kindly guide me how to properly use UIAlertController using Objective C.
Thanks,
Abin Koshy Cheriyan
Yes as per #Alexander you should not be dismissing the alert controller like this explicitly.
As per an apple engineer a new window gets added each time an UIAlertController is displayed so when we go for dismissing it the window is still there though the alert controller disappears.
So there are two ways to handle this -
Way 1 - No explicit dismiss
Do not explicitly dismiss the UIAlertController, let it be done by the user
Way 2 - Use your own window
Simply create a category on UIAertController
Here is the sample code -
.h
#import <UIKit/UIKit.h>
#interface UIAlertController (MyAdditions)
#property(nonatomic,strong) UIWindow *alertWindow;
-(void)show;
#end
In .m
#import "UIAlertController+MyAdditions.h"
#import <objc/runtime.h>
#implementation UIAlertController (MyAdditions)
#dynamic alertWindow;
- (void)setAlertWindow:(UIWindow *)alertWindow {
objc_setAssociatedObject(self, #selector(alertWindow), alertWindow, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (UIWindow *)alertWindow {
return objc_getAssociatedObject(self, #selector(alertWindow));
}
- (void)show {
self.alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.alertWindow.rootViewController = [[UIViewController alloc] init];
// window level = topmost + 1
UIWindow *topWindow = [UIApplication sharedApplication].windows.lastObject;
self.alertWindow.windowLevel = topWindow.windowLevel + 1;
[self.alertWindow makeKeyAndVisible];
[self.alertWindow.rootViewController presentViewController:self animated:YES completion:nil];
}
-(void)hide {
self.alertWindow.hidden = YES;
self.alertWindow = nil;
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// just to ensure the window gets desroyed
self.alertWindow.hidden = YES;
self.alertWindow = nil;
}
To show the alert controller
UIAlertCntroller *alert = ## initialisation##;
// will show the alert
[alert show];
//to dismiss
[alert hide];
[alert dismissViewControllerAnimated:YES completion:nil];
Even you can checkout one of my sample implementation here
I don't know about your problem, but you shouldn't do that
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
It will be anyway dismissed on any of your actions.

iOS6 problems to Tweet in UITabBarController using image taken from UIImagePickerController

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]];
}
}];

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