iOS- sharekit - settings facebook - ios

I have a sharekit implementation where everything works fine, but if there is no account set for facebook, upon pressing the settings button, the actionsheet is just dismissed and the user is returned to the app, not to the settings page in system prefs.
How do I get the settings button to send the user to the settings page?
the code i use to init the action sheet:
NSURL *url = [NSURL URLWithString:#"http://test"];
SHKItem *item = [SHKItem URL:url title:#"test"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromTabBar:self.tabBarController.tabBar];

This is a known, unresolved issue with ShareKit. You could submit a pull request to fix it, or work around it by checking SLComposeViewController:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// show ShareKit
} else {
// tell them to get Facebook
}
before displaying ShareKit. Of course, that would make it so users without Facebook (like Twitter-only folks) couldn't use ShareKit. On the other hand, you could switch over to Apple's Share Sheets, or write your own, but those also have their disadvantages. Kind of a catch-22.

Related

IOS Facebook SDK : what wrong with sharerDidCancel:(id<FBSDKSharing>)sharer delegate?

I use facebook sdk worked well except for delegate "sharerDidCancel:(id)sharer".
When i cancel my share with native dialog FB app, the delegate "sharer:(id)sharer didCompleteWithResults:(NSDictionary *)results" always called ? So i can't handle my users when they post or cancel the dialog share, is this a bug of Facebook SDK for IOS ?
Thanks for any helping!
I faced same issue during sharing in iOS 11. I have just changed native FB dialog to web dialog. As below:
Use below method:
dialog.mode = FBSDKShareDialogMode.feedWeb
instead of
dialog.mode = FBSDKShareDialogMode.native
Below is my code.It's work fine for me.
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.quote = "My Text"
content.contentURL = NSURL(string: String(format:"My Url"))! as URL!
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = content
dialog.delegate = self
dialog.mode = FBSDKShareDialogMode.feedWeb
dialog.show()
I've just been digging through the Facebook SDK docs and found this:
sharer:didCompleteWithResults: when the user successfully shares. Furthermore there will also be a postId key in the results dictionary if the user gave the app publish_actions permissions. If that user has not logged in with Facebook Login, this method will also be called if the user clicks on Cancel.
So, unless you're logged in, checking cancel won't work (which is rubbish). Looks like you might be able to give some permissions and then check the postId though.
I found it is useful when you use FBSDKShareDialogModeWeb to share a link and FBSDKShareDialogModeNative to share a photo, then when you click cancel button, it will return to canceled delegate. But it only worked before iOS 9.1, and not support on iOS 9.1. I don't know why and how to solve it yet. Hope this answer is helpful.
I found a solution for this issue. Please match facebookdiplayname name in xcode plist and facebook developer account. If facebookdiplayname same then facebook delegate methods working right way.
I also have found that sharerDidCancel is never called when canceling.
You can do like Tejvansh suggested but checking if results is nil won't work because it's not nil when the user cancels, just empty.
The way I'm doing it is to check if the key "postId" exists, in which case the post was successful otherwise I assume the user canceled.
Swift example:
func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject : AnyObject]!) {
println("sharing results \(results)")
if results["postId"] != nil {
println("shared")
} else {
println("canceled")
}
}

Pinterest Integration in iOS

I have integrated Pinterest in my application. Pinterest app is retrieving image (from url which I have shared) in popup but its not retrieving description text when Pinterest button is clicked in application. And it is forcing to enter description manually. I want description to be retrieved from application.
[_pinterest createPinWithImageURL:[NSURL URLWithString:#"http://placekitten.com/500/400"]
sourceURL:[NSURL URLWithString:#"http://placekitten.com"]
description:#"Pinning from Pin It Demo"];
This works for me.
_pinterest = [[Pinterest alloc] initWithClientId:#"1234567" urlSchemeSuffix:#"prod"];
[_pinterest createPinWithImageURL:[NSURL URLWithString:#"http://cs303404.vk.me/v303404440/1ae3/ZkKQLEFGeyY.jpg"]
sourceURL:[NSURL URLWithString:#"http://placekitten.com"]
description:#"Pinning Test from My Own App - Renish Dadhnaiya"];

Unable to post to Facebook using UI Activity View Controller

I am trying create a "share your score post" for my app to post on Facebook and twitter.I am using activity view controller, But I am having problems when I try to post it to Facebook(I have no problem posting to twitter with the url that I want). I searched for this issue but I couldn't find useful information that would fix my problem.
Code:
NSString *SharedContent =[NSString stringWithFormat: #"I just got %# points in myapp.\n Think you can do better? %# ",[formatter stringFromNumber:_LastGameResult.TotalScore],[NSURL URLWithString:#"http://myapp.co/Home/GetApp"]];
NSArray * applicationActivities = nil;
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[SharedContent,[modelClass GetImage]] applicationActivities:applicationActivities];
[self presentViewController:activityViewController animated:YES completion:nil];
For some reason Facebook doesn't accept when my url is http://myapp.co/Home/GetApp but I am able to post when the url is http://myapp.co/
my question
I need to able to post using http://myapp.co/Home/GetApp url. How can I achieve this?
Are you sure to have a Facebook account set on on your device (in the settings app)? It is easy to forget on a simulator :-)

Facebook iOS Select Friends Table Blank

I am trying to add the "select friends" to my iOS app. I set up the login view. Once I login I open the friend picker but it comes up blank. I see the table with the done and cancel buttons but there are no friends loaded into the table.
- (IBAction)selectFriendsButtonAction:(id)sender {
if (self.friendPickerController == nil) {
// Create friend picker, and get data loaded into it.
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = #"Select Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
[self.friendPickerController clearSelection];
[self presentViewController:self.friendPickerController animated:YES completion:nil];
}
Prior to opening the friend picker controller ensure your Facebook session is active by calling this:
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// Handle error
}];
}
There's two things you need to take care of that you may well not realize you need even if you understand the rest of the Facebook SDK pretty well.
The dialog will only show friends that have also installed the app.
You have to ask for the user_friends permission during your login flow.
For 1., create or use a test user you already have and run your app with that user in order to authorize the app for basic access ("install" it).
For 2, add that permission to your login flow, log out and back in with the sender you're testing (probably your own user), and if you don't get prompted to grant it even then, uninstall the app via https://www.facebook.com/settings/?tab=applications.
http://www.brianjcoleman.com/tutorial-get-facebook-friends-in-swift/ discusses some of this. The Facebook docs themselves either don't mention the 2 issues at all or it's buried.
If you use "FBFriendPickerViewController", it seems return friends who also use this APP. In Facebook document: after API Graph v2.0, "me/friends" will only return friends that also use the app. I think that's why the friend table is blank.
There is another option that you can use "FBTaggableFriendPickerViewController" instead. But your APP will need to be reviewed by Facebook before it can get data back. (https://developers.facebook.com/docs/graph-api/reference/v2.2/user/taggable_friends?locale=zh_TW)

ios-Facebook SDK 3.0 Error 5 When Posting Status Update

I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.
(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:#"status_update", nil];
FBLoginView *loginview =
[[FBLoginView alloc] initWithPermissions:perms];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:#"Test staus update"];
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
}
- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {
NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = #"Error";
} else {
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:#"Successfully posted '%#'.\nPost ID: %#",
message, [resultDict valueForKey:#"id"]];
alertTitle = #"Success";
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks
com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.
Several Possible Reasons
Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5
If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using
Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say #”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.
Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account
It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.
If I will find any extension to limit settings I will reply.
Also Facebook doesn't allow for the same Post.
Use a proxy !
FB ios SDK is just a wrap to an HTTP request to graph.facebook.com/....?access_token=.....
So you can easily replicate the request or use an HTTP proxy to see the real server answer (which is not error 5 !).

Resources