Unable to post to Facebook using UI Activity View Controller - ios

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 :-)

Related

objective c - Open with suggestions when trying to open URL schemes

I started an application that can handle SMS or Mail url schemes but I don't want to open the default apps installed. I have tried doing this
[[UIApplication sharedApplication] openURL: url];
but this opens the default SMS and Mail apps.
I tried using the UIActivityViewController
NSString *url=#"mailto:sample#gmail.com";
NSURL *schemeURL = [NSURL URLWithString:url];
NSString * title =[NSString stringWithFormat:#"Send Email",url];
NSArray* dataToShare = #[url];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil]
but this doesn't prefill the recipient field with the specified email.
It would be nice if the behaviour is the same with UIActivityViewController but let's us prefill information such as recipient.
Any suggestions ?
You can use non-default apps on macos but I don't think you can do so on iOS. Have a look at e.g. https://developer.apple.com/documentation/uikit/uiapplication/1648685-openurl?language=objc .
You could try with a URL similar to below to send with a given subject and body.
#"message://mailto://sample#gmail.com?subject=Subject&body=Body"
I think if you drop the message bit it will still work. I use it like that inside a HTML page inside an app somewhere.
If you need any special characters you will have to encode them in the subject and body.

Facebook's "Messaging an Open Graph message" functionality keeps on returning to my app

I'm trying out Facebook's new Messaging an Open Graph message, which means one can now send open graph stories to friends via the Facebook Messenger app.
In my case, I am building an app where people create a playlist and can then invite others to contribute songs to that said playlists. Therefore, an interesting path to take is being able to post an open graph message via Facebook Messenger to one's friends.
I have set up a Create action, a Playlist object and a Create a Playlist story.
The code I use in the iOS app is very close to the one provided as an example by Facebook:
Creating the playlist object:
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"vibe-social-music:playlist"
title:#"Sample Playlist"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:#"http://samples.ogp.me/616101581814728"
description:#""];
Creating the action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"playlist"] = object;
Creating the params:
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"create"
previewPropertyName:#"playlist"];
Calling the 'present message' dialog within the messenger app:
[FBDialogs
presentMessageDialogWithOpenGraphActionParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
//TODO: Handle errors
NSLog(#"error: %#", error);
} else {
NSLog(#"results: %#", results);
}
}];
As I explained before, the Facebook messenger app opens, but quickly returns back to my application.
I have the Facebook credentials well setup in my Info.plist file.
The one thing is that the action is not yet validated by Facebook. Could that be an issue?
Otherwise, I'm at a loss as to why it won't show an Open Graph story in the Messenger app, and why it always goes back to my application.
Any help would be greatly appreciated, thanks!
Can you confirm you configured a custom story in the Open Graph section of your app settings (and not just the action and object types)?
Also, it looks like the action type is missing your app namespace in the params construction: i.e.,
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"vibe-social-music:create"
previewPropertyName:#"playlist"];

iOS - Facebook open graph sharing via app is successful, but does not look the way I want it to on Facebook

I have an iPhone app that is used for taking photos. I just finished adding the Facebook sharing functionality to this app.
I went through this entire page here: https://developers.facebook.com/docs/ios/open-graph
I followed all of the instructions, and copied and pasted the code into xcode. The only thing I didn't do was the one part at the very bottom of the page called "Deep Linking", but that is not important right now.
After doing all of this, my app can successfully share an image to facebook. However, it is not being shared the way I need it to.
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
Here is a screenshot showing where the share is located on my facebook page when viewed on a Desktop computer:
And here is how the share looks when using the Facebook App for the iPhone (I blacked out my name):
These both look terrible. Here are 2 examples of what I want to accomplish.
Here is how a photo from this app called "Frontback" looks when I share it to my page and view on a Desktop computer:
And it looks the same on the Facebook App for the iPhone as well.
The only difference I can tell is that the URL for my shares has "/activity/" in it, where as the Frontback app shares have "photo.php" in their Facebook URL's.
I can't figure out how to get my app's shares to look like the shares from the Frontback app.
Any help is greatly appreciated thank you.
The posts that you created seems meaningful to me. An open-graph feed is always beautiful and more meaningful than the normal feed.
What Frontback post you are seeing is simple photo upload, that's not a feed. I mean it all depends on your requirement, what exactly your app will want to do.
If you just want to show some photos via your app like Frontback, you can avoid open graph and publish photos using the API \POST /photos.
But if you want to give a link that could redirect the user to the app you should use what you are using right now.
Another thing, when you said-
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
That's the beauty of open-graph, it clubs all the activities of an app in your timeline, not unnecessarily making status updates and flooding your timeline. The stories appear on top in your/your friends wall and the ticker. You can also see the actual story by clicking on the time in the story of your activity log-
(activity log)
(actual story)
- (void)requestPermissionAndPost {
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObjects:#"publish_actions", #"publish_checkins",nil]
defaultAudience:FBSessionDefaultAudienceEveryone
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Now have the permission
[self postOpenGraphAction];
} else {
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
[self presentAlertForError:error];
}
}
}];
}
- (void)postOpenGraphAction
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:#"me" result:result error:error];
};
UIImage *img = imageView.image;
NSString *message = [NSString stringWithFormat:#"%# %# #DealsHype",msg.text,hashtagFromStore];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/photos" parameters:[NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation(img, 0.7),#"source",message,#"message",#"{'value':'EVERYONE'}",#"privacy", nil] HTTPMethod:#"POST"];
[newConnection addRequest:request completionHandler:handler];
[self.requestConnection cancel];
self.requestConnection = newConnection;
[newConnection start];
}
this is the good to upload image with some message .. if you want to upload a big image like Frontback

iOS- sharekit - settings facebook

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.

iOS Facebook SDK - Posting A UIImage To User's Wall

Ok so there is a lot of threads on this, but nothing seems to work for me.
My app allows users to post a photo (which is a UIImage created by a screenshot of the App) to facebook.
However, I can currently only post the photo by using:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[appDelegate facebook] accessToken], #"access_token",nil];
[params setObject:#"Caption" forKey:#"name"];
[params setObject:[self captureScreen] forKey:#"source"];
if([[appDelegate facebook] requestWithGraphPath:#"me/photos" andParams: params andHttpMethod: #"POST" andDelegate:(id)self]){
[self.view addSubview:[Memos showMemo:facebookMemo]];//Show success alert
}
This works fine, but doesn't use any sort of FB Dialog.
I really want to use the dialog so users can feel like it is more "facebook official" and allow them to preview/confirm the post.
Is there any SIMPLE way to go about doing this?
This is the closest I have gotten: Post photo on user's wall using Facebook iOS SDK, but I have issues with these lines:
currentAPICall = kAPIGraphUserPhotosPost;
As xcode doesnt recognize any of the kAPI... objects...
Suggestions?

Resources