FBSDKShareDialog of Facebook SDK is not working on iOS9? - ios

With Xcode7, I upgrade Facebook SDK to pod FBSDKShareKit (4.6.0). And I have added Facebook scheme to WhiteList as below.
reference: https://developers.facebook.com/docs/ios/ios9
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
However, the following code only show iOS default social dialog on iOS9. The same code with the same binary on iOS8 can open Facebook app and show the Sharing Dialog properly.
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.example.com"]];
content.contentDescription = #"Test";
[FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];
I guess Facebook app is not found on iOS9 and then show the default social dialog. Even no error message showed.
Do I miss anything? Or, it's an iOS9 bug?

I'm guessing Facebook changed the behaviour because iOS 9 now pops up a dialog asking if you would like to "Open Facebook?" when doing app-switching. Even for FBSDKLoginManager, the app-switching (native) method seems to be less preferred than a modal UIWebView.
However, you can still force the share dialog to switch to the Facebook app (assuming you have your application plist setup as described in https://developers.facebook.com/docs/ios/ios9) by using this method:
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fbauth2://"]]){
dialog.mode = FBSDKShareDialogModeNative;
}
else {
dialog.mode = FBSDKShareDialogModeBrowser; //or FBSDKShareDialogModeAutomatic
}
dialog.shareContent = content;
dialog.delegate = self;
dialog.fromViewController = self;
[dialog show];

In iOS 9 below is the only solution that worked for me to detect if facebook app is installed in the device or not:
NSString *urlString = #"fbapi://";
NSURL *url1 = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url1]) {
[[UIApplication sharedApplication] openURL:url1];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itunes link for download app"]];
}

Related

Facebook post do not open my application when i try from safari even though it works when using facebook application.

I have shared some content to Facebook and I am using this POC for that.
NSString *title = #"Some Title";
NSString *shareBody =[NSString stringWithFormat:#"%#\nI have rated %# as %zd/5", self.commentTextView.text, store.name, self.rating];
NSString *storeID = store.ID.description;
FBSDKShareLinkContent *content = [FBSDKShareLinkContent new];
content.contentTitle = title;
content.contentDescription = shareBody;
content.imageURL = [NSURL URLWithString:store.coverImage.medium];
content.placeID = storeID;
content.contentURL = [NSURL URLWithString:[NSString stringWithFormat:#"https://fb.me/ 137144****85103?store=%#", store.ID]];
FBSDKShareDialog* dialog = [FBSDKShareDialog new];
dialog.delegate = self;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeBrowser;
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fbauth2://"]])
dialog.mode = FBSDKShareDialogModeAutomatic;
dialog.fromViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
Post is successfully shared to Facebook even if Facebook app is installed or not.
The first case is when I am using Facebook app and i click on the shared post, it opens my application(if it is installed) or takes me to iTunes URL.
The second case is Facebook app is not installed on my phone and I use safari to view Facebook and I click on that post. It tries to open the url but redirect me to facebook.com again.
The third case is Facebook app is installed on my phone but still I use safari to view Facebook and I click on that post, it opens facebook app instead of my app.
I need help for Case 2 and 3. Please advise ?

Facebook Deep Linking is not opening the app

I am sharing my post on Facebook. I am sharing Image, Content URL, Description. I am using this code for sharing:
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = APP_NAME;
content.contentDescription = text;
content.imageURL = [NSURL URLWithString:[[arrAllEvents valueForKey:#"flyer_image"]objectAtIndex:0]];
content.contentURL = url;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeFeedWeb;
[dialog show];
I have enable Deep Linking (News Feed links launch this app) option for https://developers.facebook.com.
I have added my Fbid and URLShema Like this
<key>CFBundleURLSchemes</key>
<array>
<string>abcevent://</string>
<string>fb1......</string>
</array>
and add code in appdelegate.m for the same like this
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url,NSError *error){
if([[url scheme] isEqualToString:#"abcevent"])
{
[self callNewsletter:url];
}
}];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[FBSDKAppEvents activateApp];
}
Now if I am sharing my post on fb via application. That post click is not opening my app in iPhone Deep linking is not working.
Can anyone tell what other things I am missing with this?
The fetchDeferredAppLink method only works with ads. It never worked with links shared organically on the News Feed. You can read about more limitations of deep linking from Facebook in this blog post, but there are two core things to know:
Facebook has never supported deferred deep linking for non-paid content.
Facebook's App Links standard at one point supported normal deep linking (meaning if the app is already installed), but this has been broken on iOS for a long time.
If you want this sort of functionality, you'll need a separate solution like Branch.io (full disclosure: I'm on the Branch team).

How to share a post to a facebook group, not my own timeline, using the Facebook SDK share dialog?

I'm trying to share a link object to a Facebook group using the share dialog. No one seems to have answered this question satisfactorily yet.
The SDK documentation clearly states that you can use the share dialog to share to your own timeline or groups, yet I can't figure out how to do it. I also don't see any other apps that do it. Using the web share dialogue on a desktop you can see the option, but on a mobile website you don't! This screenshot of the iOS Facebook app shows what I'm talking about:
I'm trying to get the functionality in where it says 'tap to change' at the top.
It appears you have to use an instance of FBSDKShareDialog, and set the mode to FBSDKShareDialogModeNative.
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = viewController;
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.test.com"];
content.contentTitle = productItem.productTitle;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeNative;
if (![dialog canShow]) {
dialog.mode = FBSDKShareDialogModeWeb;
}
dialog.delegate = self;
[dialog show];

Using Google+ SDK in iOS apps

Google plus SDK has been integrated in one of my apps for sharing the app content.
For this user has to login into Google plus account on the app and then use this sharing feature.
But, in the Google developer site it says that Google Plus login is deprecated and we need to implement Google login instead of Google Plus login.
I am not using Google Plus just for a login functionality.
So, what should i do now?
There's a GoogleSignIn SDK: https://developers.google.com/identity/sign-in/ios/start-integrating.
If you are just interested in sharing you should probably be using the SFSafariViewController to present the share dialog box in a webview:
- (void)showGooglePlusShare:(NSURL*)shareURL {
// Construct the Google+ share URL
NSURLComponents* urlComponents = [[NSURLComponents alloc]
initWithString:#"https://plus.google.com/share"];
urlComponents.queryItems = #[[[NSURLQueryItem alloc]
initWithName:#"url"
value:[shareURL absoluteString]]];
NSURL* url = [urlComponents URL];
if ([SFSafariViewController class]) {
// Open the URL in SFSafariViewController (iOS 9+)
SFSafariViewController* controller = [[SFSafariViewController alloc]
initWithURL:url];
controller.delegate = self;
[self presentViewController:controller animated:YES completion:nil];
} else {
// Open the URL in the device's browser
[[UIApplication sharedApplication] openURL:url];
}
}

using google map api with X-callback url

I am working on a navigation app which launches GOOGLE MAP from my native app when user click on any of the pins displayed on the apple map. The location data was pulled from GOOGLE. So I used this code for block showing a callout accessory and let user get to the GOOGLE MAP
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
NSString* addr = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr", view.annotation.coordinate.latitude,view.annotation.coordinate.longitude];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
Then I found out there is a x-callback url which can put a back button in the google map and let the user go back to my native app. but anyone know how to use these lines of codes? i have registered my app in the properties list but i have no idea what to do the next. the code from google is like this:
comgooglemaps-x-callback://?center=40.765819,-73.975866&zoom=14
&x-success=sourceapp://?resume=true
&x-source=SourceApp
Can anyone please tell me where shall i put these codes? and How to use that in my app?
If you scroll down in the Google documentation they give example code on how to use this in iOS.
Code provided:
NSURL *testURL = [NSURL URLWithString:#"comgooglemaps-x-callback://"];
if ([[UIApplication sharedApplication] canOpenURL:testURL])
{
NSString *directionsRequest = #"comgooglemaps-x-callback://" +
#"?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York" +
#"&x-success=sourceapp://?resume=true&x-source=AirApp";
NSURL *directionsURL = [NSURL URLWithString:directionsRequest];
[[UIApplication sharedApplication] openURL:directionsURL];
}
else
{
NSLog(#"Can't use comgooglemaps-x-callback:// on this device.");
}
You would change everthing after daddr= with your address. Also change AirApp to the name of your application.
you should use below code :
NSURL *testURL = [NSURL URLWithString:#"comgooglemaps-x-callback://"];
if ([[UIApplication sharedApplication] canOpenURL:testURL])
{
NSMutableString *directionsRequest = [NSMutableString stringWithString:#"comgooglemaps-x-callback://"];
[directionsRequest appendFormat:#"?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York"];
[directionsRequest appendFormat:#"&x-success=CouriorMap://?resume=true&x-source=AirApp"];
NSURL *directionsURL = [NSURL URLWithString:directionsRequest];
[[UIApplication sharedApplication] openURL:directionsURL];
}
else
{
NSLog(#"Can't use comgooglemaps-x-callback:// on this device.");
}
To use the google map call back function:
Add the following content to info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.example.GoogleMapTest</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp</string>
</array>
</dict>
</array>
</dict>
</plist>
com.example.GoogleMapTest is you app bundle id.
myapp is the url scheme just like google map's comgooglemaps://.
Call the function anywhere you wish:
- (void)useGoogleMapApp {
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"comgooglemaps://"]]) {
NSString *url = #"comgooglemaps-x-callback://?saddr=1.294094,103.853722&daddr=1.244310,103.833386&directionsmode=transit&x-success=myapp://?resume=true&x-source=MyAppName";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
} else {
NSLog(#"Can't use comgooglemaps://");
}
}

Resources