post image to facebook page - iphone

Im using SocialFramework for posting image to facebook. When i click the button the facebook page is opening. But my need is, i need to share my image to not in my wall, share to following facebook page https://www.facebook.com/Google
code:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"My image"];
[controller addImage:newImage.image];
[self presentViewController:controller animated:YES completion:Nil];
}

Related

SLServiceTypeFacebook in SLComposeViewController hang my iphone app

I have implemented Facebook sharing in my app. But When composerview is opened and i tapped on post, after that it will block my app. I am not able to navigate to other view controller. Here is the code that i have used:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
} else {
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:strMsg];
[vc presentViewController:controller animated:YES completion:Nil];
I faced the same issue and debugged as well. In my case it was not a hang; after the SLCompeseViewController disappeared (moved up the screen) there were some UIViews, UIControls remaining on the controller.view which hinder user interaction (i think it is the same in your app).
If it is the same case, you will never be able to remove those Views because the completion handler is never called.
This is a bug in iOS8, here is the link.
https://developers.facebook.com/bugs/962985360399542/?search_id
I suggest you to use UIActivityViewController instead of SLComposeViewController.

How to share app

I'm developing an app. I'm going to publish to an app store. But client needs to share this app with friends. I have a button to share my app. How to share the app? I read some doc they mentioned, use [[UIApplication SharedApplication] openURL:#" url"]. I don't have my app URL. Because I didn't submit the app. Is it possible to share my app?
If you want to know what the URL of your application will be before it has been submitted/approved, Apple provides a shorthand URL you can use, of the form:
http://itunes.com/apps/appname
For example:
http://itunes.com/apps/AngryBirds
If you want the specific URL with the application ID, you could submit v1.0.0 without the "Share" link, then immediately submit a 1.0.1 update with the link included.
Url can be generated via app id. Its the best way to do it coz if app name changes, url could change. But app id wont change.
You can get your app id on itunesConnect.apple.com or via itunes.
//https://itunes.apple.com/app/id_hereisyourappID
Let see how to do the sharing.
I will show you 4 ways to share your link. Via Facebook, Twitter, Mail and SMS.
For Facebook and Twitter.
Add Accounts and Social framework. And in your header import.
#import <Social/Social.h>
#import <Accounts/Accounts.h>
when you want to share link use the following code
SLComposeViewController *mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];//for twitter use SLServiceTypeTwitter
[mySLComposerSheet addURL:[NSURL URLWithString:#"https://itunes.apple.com/app/id123456789"]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
Lets do it with mail add MessageUI framework and import
#import <MessageUI/MessageUI.h>
And the delegate MFMailComposeViewControllerDelegate
in your code
MFMailComposeViewController* mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setMessageBody:#"https://itunes.apple.com/app/id123456789" isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
And add delegate method
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
You can create html content for mail body.
Lets share it via SMS
Add delegate MFMessageComposeViewControllerDelegate
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"https://itunes.apple.com/app/id123456789";
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
And add delegate method.
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
I hope this helps.

Social framework - how to know if message was sent or not

I'm using Social framework in my project (iOS6), so user can make posts on Facebook or Twitter.
My question is, if there is a way to find out if user have sent a post to social network or he have canceled it and haven't published anything?
I use this code to share posts on Twitter:
-(IBAction)askOnTwitter
{
if (SYSTEM_VERSION_LESS_THAN(#"6.0"))
{
[self showErrorAlert];
twitterButton.enabled = NO;
return;
}
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setInitialText:#"Hey"];
[self presentViewController:slComposeViewController animated:YES completion:nil];
// So have user published a post or he haven't? How to know?
}
}
Does somebody know the trick? Thanks in advance.
You can set the completion handler for your compose view controller. There you will get the result SLComposeViewControllerResultDone or SLComposeViewControllerCancelled
__block __weak SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[slComposeViewController setCompletionHandler:^
(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultDone) {
NSLog(#"Done successfully");
}
else{
NSLog(#"Cancelled");
}
[slComposeViewController dismissViewControllerAnimated:YES completion:nil];
}];

how to display app name in place of "ios" during facebook sharing

I am using this code the sharing happens but it shows ios as the application.How can it display my application name ?
- (IBAction)postToFacebook:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[self presentViewController:controller animated:YES completion:Nil];
}
}
You have to register your app on Facebook for that and have to share through Facebook SDk ( not Social framework).
Facebook sdk tutorial is here

iOS - Posting to Facebook... is the icon this one?

I am posting to Facebook using the social api of iOS 6.
I am using the tradicional SLComposeViewController, like in..
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
...
at some point I do
[controller addImage:imageFacebook];
where imageFacebook is a screenshot that is 280 pixels high and then I post to Facebook.
My problem is this. I am following similar approach with the twitter API, but when that little window shows, there is a thumbnail of the image I am sending, hold by a clips on the right side, but on the facebook counterpart I see this safari-like icon. Is this normal? I would be a happy man if I was seen here a miniature of the image being posted, as I saw with the twitter API...
NOTE: the image is being posted correctly to Facebook... my problem is this icon on the posting window.
Is there a way to change that icon?
thanks
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(#"Cancelled");
} else {
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:#"Enter Your Text Here:"];
[controller addURL:[NSURL URLWithString:#"http://www.google.com"]];
[controller addImage:[UIImage imageNamed:#"image001-794043.jpeg"]];
[self presentViewController:controller animated:YES completion:Nil];
} else {
NSLog(#"UnAvailable");
}