iOS Facebook SDK 4 FBSDKShareDialog - ios

I have some trouble when I try to implement FBSDKShareDialog to perform facebook sharing via my app. If official fb app is installed it shows blank dialog (where user allows to type some text etc). If user doesn't have fb app it shows correct info but FBSDKSharingDelegate methods doesn't work. (It doesn't work even when user has fb application)
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"complete");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
NSLog(#"did cancel");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NSLog(#"%#", error);
}
It's never called even when I cancel or share via FB application.
My code is:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = _place.title;
content.imageURL = [NSURL URLWithString:_place.logoUrl];
content.contentDescription = _place.info;
[FBSDKShareDialog showFromViewController:_viewController withContent:content delegate:self];
I have a delegate inside #interface declaration.
#interface FacebookHandler () < FBSDKSharingDelegate >
#end
My app delegate has
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Where I was wrong? And is it good idea to post some image and title via FBSDKShareLinkContent. Thanks in advance.

Are you calling [FBSDKShareAPI shareWithContent:content delegate:self] from the main thread?

I've already fixed this issue. The problem was that I've delegate to file inherited from NSObject, which can't be a delegate

Related

Not Able To Implement Google Sign In for iOS App

I am following all steps as per this link Click here
After doing all steps it gives me
Can anyone tell me this strange is happening ?
Answer would be appreciated.
Thanks.
Try those:
Add GIDSignIn library header properly, if in case you missing something.
Add AppDelgate.h file into your ViewController (If you not writing this code in AppDelegate.m)
Read point 4 which I copied from GitHub forum, which can be the main reason of your errors.
It looks like iOS 9 changed the constant UIApplicationLaunchOptionsSourceApplicationKey to UIApplicationOpenURLOptionsSourceApplicationKey. Dynamically support both, especially in Xcode 6.4 which doesn't recognize UIApplicationOpenURLOptionsSourceApplicationKey.
After try these all if its still not working then comment here for further help.
This is the AppDelegate.m file from which I implemented Google Signin SDK (the new one)
#define kGoogleClientID #""
#import "AppDelegate.h"
#import <GoogleSignIn/GoogleSignIn.h>
#interface AppDelegate ()<GIDSignInDelegate>
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GIDSignIn sharedInstance].clientID = kGoogleClientID;
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if(annotation){
NSDictionary *options = #{UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication,
UIApplicationOpenURLOptionsAnnotationKey: annotation};
return [self application:application
openURL:url
options:options];
}
}
/* Google */
- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations on signed in user here.
// ...
}
- (void)signIn:(GIDSignIn *)signIn
didDisconnectWithUser:(GIDGoogleUser *)user
withError:(NSError *)error {
// Perform any operations when the user disconnects from app here.
// ...
}
#end
Hope this helps you out

facebook native ap is not launched in fb login in iOS?

I have implemented facebook api in my app to support facebook login. When I tap the facebook button then it launches a safari it does not redirect to my native facebook app. I have installed facebook app & logged in.
I have used following code
// Do any additional setup after
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.delegate=self;
loginButton.readPermissions =
#[#"email", #"user_friends"];
[self.view addSubview:loginButton];
How can I launch the fb native app?
EDIT:
AppDelegate code
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[FBSDKAppEvents activateApp];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
#end
Maybe you are missing this in your appdelegate.m ?
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

FBSDKAppInvite call back is not get in ios

I am beginner in IOS and want to invite friend via facebook for used my application. I used new framework of the facebook(4.0) and i found that for invite i need to used FBSDKAppInvite.
I setup the deep link in "Quick Start for App Links Hosting API".
I used following code for application invite
#pragma mark
#pragma mark - Share via facebbok
- (IBAction)btnShare:(id)sender
{
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"https://fb.me/863075563772717"];
//optionally set previewImageURL
// present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate`
[FBSDKAppInviteDialog showWithContent:content
delegate:self]; // Do any additional setup after loading the view, typically from a nib.
}
-(void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
NSLog(#"result::%#",results);
}
-(void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error
{
NSLog(#"error::%#",error);
}
And handle callback in following method
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// Check if the handler knows what to do with this url
BFURL *parsedUrl = [BFURL URLWithInboundURL:url sourceApplication:sourceApplication];
if ([parsedUrl appLinkData]) {
// this is an applink url, handle it here
NSURL *targetUrl = [parsedUrl targetURL];
[[[UIAlertView alloc] initWithTitle:#"Received link:"
message:[targetUrl absoluteString]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] show];
}
return YES;
}
But i get nil in [parsedUrl appLinkData]
I am not understand what i do wrong. I also put URLScheme in Plist.
Any help can be appreciable
UPDATE
if i used following method then i get success in delegate method but invite is not send to recipient.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// Check if the handler knows what to do with this url
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

Facebook SDK share always returns sharerDidCancel [duplicate]

This question already has answers here:
FBSDKShareDialog cancels when it should post
(4 answers)
Closed 7 years ago.
I'm trying to share a post with the Facebook SDK, but sharerDidCancel is always called, either if I share or cancel the post.
Here is my code
- (void)shareFacebook {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:#"http://www.google.com"];
[FBSDKShareDialog showFromViewController:view
withContent:content
delegate:self];
}
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary*)results {
NSLog(#"FB: SHARE RESULTS=%#\n",[results debugDescription]);
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(#"FB: ERROR=%#\n",[error debugDescription]);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(#"FB: CANCELED SHARER=%#\n",[sharer debugDescription]);
}
This class implements the FBSDKSharingDelegate, in my Info.plist I already entered the FacebookAppID and FacebookDisplayName.
In my AppDelegate I have this method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
What I'm doing wrong? I exactly followed the Facebook SDK guide.
Thanks
Solved, my error was in the AppDelegate method:
here is a link with the solution http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html
And here is the code
- (BOOL)application:(UIApplication *)application openURL:(NSURL* )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url sourceApplication:sourceApplication annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [ [FBSDKApplicationDelegate sharedInstance] application :application
didFinishLaunchingWithOptions:launchOptions]
}

Facebook share dialog callback not working in iOS

I'm implementing the share dialog using the Facebook SDK for iOS.
Everything works fine except for the callback.
This is the function that displays the dialog:
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = <my content url>;
content.contentTitle = <my title>;
content.contentDescription = my description;
content.imageURL = <my image url>;
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
The view controller implements the FBSDKSharingDelegate and the three required methods:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results;
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error;
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;
Basically I have to detect if users pressed the cancel button because I give them a reward only if they effectively share the content.
The problem is that even if I press the cancel button the only callback that is invoked is:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results;
and not
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;
as expected. Furthermore using iOS8 the variable results is empty if the cancel button is pressed, otherwise it contains the post_id, but this does not happen with iOS7, where the result is always empty.
What am I doing wrong? What am I supposed to do to have the sharerDidCancel callback working properly?
Thanks for any help!
Try entering this to your appdelegate. It worked for me to call the right delegate but the result dictionary is still empty and I can't get the post_id.
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

Resources