Sometimes the Facebook share dialog doesn't load on iOS - iphone

Sometimes when I launch the Facebook share dialog, the OS switches to the Facebook app, but the share dialog doesn't load. Then if you try again, it usually works. Why doesn't it work the first time?
NSURL* url = [NSURL URLWithString:#"some URL"];
FBShareDialogParams* params = [[FBShareDialogParams alloc] init];
params.link = url;
if ([FBDialogs canPresentShareDialogWithParams:params]) {
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error posting to FB: %#", error.description);
//do something
} else {
//do something else
}
}];
// }
}

This class is no longer available in the most recent version of the SDK.
You should use FBSDKShareDialog instead of this.The latest version is v4.11.0.
Thanks.

Related

Share UIImage using FBWebDialogs using Facebook SDK in ios 7

I am trying to share the local UIImage using FBWebDialogs. But I am getting any solution which will share the local image using FBWebDialogs. Can anybody tell me , how can I share local UIImage using FBWebDialogs ?
Note: My iOS app is totally local. So I can't get the image URL.
Here is my code
-(void)shareInformationUsingFeedDialogWithParameters:(NSDictionary*)params
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
[self showAlertWithTitle:#"Error" andMessage:#"An error occured while sharing information using Facebook"];
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
[self showAlertWithTitle:#"Alert" andMessage:#"You cancelled the Facebook sharing"];
}
else
{
[self showAlertWithTitle:#"Success" andMessage:#"Facebook sharing successful"];
}
}
}];
}

show app name on facebook share iPhone

I am using facebook.framework i want to share image using native facebook Dialog of iOS 6.0
I can share image but i want to show my app name.... like currently it showing via ios....
I6+
+65 want to show app name..Like via xyz... I am using below code.....
- (IBAction)publishButtonAction:(id)sender {
// Try and present the iOS Share Sheet
[FBDialogs
presentOSIntegratedShareDialogModallyFrom:self
initialText:#"" image:[UIImage imageNamed:#"iossdk_logo.png"]
url:[NSURL URLWithString:#"https://developers.facebook.com/ios"]
handler:^(FBOSIntegratedShareDialogResult result, NSError *error) {
NSString *alertText = #"";
if ([[error userInfo][FBErrorDialogReasonKey]
isEqualToString:FBErrorDialogNotSupported]) {
alertText = #"iOS Share Sheet not supported.";
} else if (error) {
alertText = [NSString stringWithFormat:
#"error: domain = %#, code = %d",
error.domain, error.code];
} else if (result == FBNativeDialogResultSucceeded) {
alertText = #"Posted successfully.";
}
if (![alertText isEqualToString:#""]) {
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:#"Result"
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil]
show];
}
}];
}
Unfortunately, you can't show your App Name if you want to use Facebook.framework and the iOS 6 default share dialog.
The only way to achieve this is to register an app on Facebook Developers and handle every connection/request using their iOS SDK.
Facebook.framework is the most straightforward way to deal with Facebook APIs but you have to renounce to your app name. Otherwise, you can take the harder way and build your app from scratch so you'll be able to show your app name. More info here: Facebook Share Dialog.

FBDialogs presentShareDialog does not work in both 5.1 and 6.1

id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"https://example.com/book/Snow-Crash.html"
forKey:#"book"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"books.reads"
previewPropertyName:#"book"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
I use the above codes to present a facebook shareDialog in my application ,but it does not work in both ios 5.1 and 6.1.I want to know the reason.
From my understanding as of now (I might be wrong), this code invokes the facebook native iOS app. If you are testing this on the simulator and don't have the iOS app installed, this will not work. It is unlikely you will be able to test this on the simulator. Try it on a real device that has the facebook iOS app installed.
Do you have the latest Facebook app installed?
Also, you're trying to post an open graph action using facebook's example action, which I'm not sure even exists. If you have registered custom open graph actions with you app, I suggest you modify your code to invoke it instead. If you don't have custom actions, I suggest starting with posting simple urls to see if it works for you.
Use:
NSURL* url = [NSURL URLWithString:#"https://developers.facebook.com/"];
[FBDialogs presentShareDialogWithLink:url
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
And lastly I suggest you read this: https://developers.facebook.com/ios/share-dialog/

How to check if Facebook is loggedIN in device ? objective C

I am implementing the Facebook SDK into my app . I am using FBLoginView to login with Facebook. I have a UIButton, which I'm using to share on a user's Facebook wall. Now I don't want to login using FBLoginView , i want to check if there is a Facebook app, and if the user has logged in.
- (IBAction)pickFriendsList:(UIButton *)sender
{
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = #"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *sender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString* fid;
NSString* fbUserName;
for (id<FBGraphUser> user in friendPickerController.selection)
{
NSLog(#"\nuser=%#\n", user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"test", #"message", #"http://webecoist.momtastic.com/wp-content/uploads/2009/01/nature-wonders.jpg", #"picture", #"Sample App", #"name",fid,#"tags",fid,#"to",#"106377336067638",#"place", nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed",fid] parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
// Error launching the dialog or publishing a story.
NSLog(#"Error publishing story.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(#"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
//Tell the user that it worked.
}
}
}];
}];
}
}];
}
I am assuming that you are using iOS 6 sdk. In which case, Use below code (workable for device) :
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
//user is already logged in using iOS integrated FB a/c
}
else
{
//user is not logged in
}
Note: FBSession can't check this criteria. So session check with FBSession has a different meaning from above code.
Regards,
Check for the URL Scheme fb://
[[UIApplication sharedApplication] canOpenURL:#"fb://"] returns YES if Facebook App is installed. This post lists, de available URL schemes for Facebook: https://stackoverflow.com/a/5707825/1511668
Maybe fb://online is what you are looking for.

Opening iTunes Store to specific song

Ok, I have seen similar questions here but none are actually answering the problem for me.
I have a streaming audio app and the stream source returns to me the song title and artist name. I have an iTunes button in the app, and want to open the iTunes STORE (search) to that exact song, or at least close. I have tried the following:
NSString *baseString = #"itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?songTerm=";
NSString *str1 = [self.songTitle2 stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSString *str2 = [self.artist2 stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSString *str = [NSString stringWithFormat:#"%#%#&artistTerm=%#", baseString, str1, str2];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:str]];
This call does indeed switch me to the iTunes STORE as expected, but then it pops up an error "Cannot connect to iTunes Store". I am obviously on-line as the song is actively streaming, and I am in the store. The search box in iTunes app only shows the song name and nothing else.
Here is an example of a generated string:
itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearchResults?artistTerm=Veruca+Salt&artistTerm=Volcano+Girls
I have tired taking the string it generates and pasting it into Safari, and it works OK on my Mac, opening to albums from the artist in the store. Why not on the phone?
Also, it seems to ignore both items, as it does not take me to the song by that artist. Does this require also knowing the album name (which I do not have at this time.)
Help would be appreciated. Thanks.
Yes, I am answering my own question.
After much digging and a talk with one of the best programmers I know, we have a solution, so I thought I would share it here. This solution takes the song name and artist, actually does make a call to the Link Maker API, gets back an XML document, and extracts the necessary info to create a link to the iTunes Store, opening the store to the song in an album by that artist that contains the song.
In the interface of the view controller, add:
#property (strong, readonly, nonatomic) NSOperationQueue* operationQueue;
#property (nonatomic) BOOL searching;
In the implementation:
#synthesize operationQueue = _operationQueue;
#synthesize searching = _searching;
Here are the methods and code that will do this for you:
// start an operation Queue if not started
-(NSOperationQueue*)operationQueue
{
if(_operationQueue == nil) {
_operationQueue = [NSOperationQueue new];
}
return _operationQueue;
}
// change searching state, and modify button and wait indicator (if you wish)
- (void)setSearching:(BOOL)searching
{
// this changes the view of the search button to a wait indicator while the search is perfomed
// In this case
_searching = searching;
dispatch_async(dispatch_get_main_queue(), ^{
if(searching) {
self.searchButton.enabled = NO;
[self.searchButton setTitle:#"" forState:UIControlStateNormal];
[self.activityIndicator startAnimating];
} else {
self.searchButton.enabled = YES;
[self.searchButton setTitle:#"Search" forState:UIControlStateNormal];
[self.activityIndicator stopAnimating];
}
});
}
// based on info from the iTunes affiliates docs
// http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
// this assume a search button to start the search.
- (IBAction)searchButtonTapped:(id)sender {
NSString* artistTerm = self.artistField.text; //the artist text.
NSString* songTerm = self.songField.text; //the song text
// they both need to be non-zero for this to work right.
if(artistTerm.length > 0 && songTerm.length > 0) {
// this creates the base of the Link Maker url call.
NSString* baseURLString = #"https://itunes.apple.com/search";
NSString* searchTerm = [NSString stringWithFormat:#"%# %#", artistTerm, songTerm];
NSString* searchUrlString = [NSString stringWithFormat:#"%#?media=music&entity=song&term=%#&artistTerm=%#&songTerm=%#", baseURLString, searchTerm, artistTerm, songTerm];
// must change spaces to +
searchUrlString = [searchUrlString stringByReplacingOccurrencesOfString:#" " withString:#"+"];
//make it a URL
searchUrlString = [searchUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* searchUrl = [NSURL URLWithString:searchUrlString];
NSLog(#"searchUrl: %#", searchUrl);
// start the Link Maker search
NSURLRequest* request = [NSURLRequest requestWithURL:searchUrl];
self.searching = YES;
[NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse* response, NSData* data, NSError* error) {
// we got an answer, now find the data.
self.searching = NO;
if(error != nil) {
NSLog(#"Error: %#", error);
} else {
NSError* jsonError = nil;
NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if(jsonError != nil) {
// do something with the error here
NSLog(#"JSON Error: %#", jsonError);
} else {
NSArray* resultsArray = dict[#"results"];
// it is possible to get no results. Handle that here
if(resultsArray.count == 0) {
NSLog(#"No results returned.");
} else {
// extract the needed info to pass to the iTunes store search
NSDictionary* trackDict = resultsArray[0];
NSString* trackViewUrlString = trackDict[#"trackViewUrl"];
if(trackViewUrlString.length == 0) {
NSLog(#"No trackViewUrl");
} else {
NSURL* trackViewUrl = [NSURL URLWithString:trackViewUrlString];
NSLog(#"trackViewURL:%#", trackViewUrl);
// dispatch the call to switch to the iTunes store with the proper search url
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:trackViewUrl];
});
}
}
}
}
}];
}
}
The XML file that comes back has a LOT of other good info you could extract here as well, including three sizes of album art, album name, cost, etc, etc.
I hope this helps someone else out. This stumped me for quite some time, and I thank a good friend of mine for making this work.
You are in fact using a URL for the search. That's why iTunes opens on search. My iTunes in Mac OS X also opens in search.
Use the Search API for iTunes to search for the content you want and get the artist, album or song ids so you can generate a direct URL for that content.
Look in the iTunes Link Maker how to create a URL for an artist or for a specific album and compose that URL on your app.
It appears that now iOS already opens the iTunes app directly when you try to open a itunes html url.
Example, trying to do a openURL on https://itunes.apple.com/br/album/falando-de-amor/id985523754 already opens the iTunes app instead of the website.