FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES
You should try adding in your AppDelegate didFinishLaunchingWithOptions :
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
This would get u [FBSDKAccessToken currentAccessToken]
when user is logged in.
and
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
If this method is not present into AppDelegate then it results into cancelled state.
Refer to : https://developers.facebook.com/docs/ios/getting-started#startcoding
Facebook login always comes back as cancelled. (iOS Swift)
I had the some problem but I found a workaround. You can set the login behaviour of the Login Manager to use the Facebook details on the phone. The default behaviour is FBSDKLoginBehaviorSystemNative and that tries to use the Facebook app first and then if its not there, it uses a web modal.
Instead of doing it that way and passing around urls that don't seem to work you can set the login behaviour as FBSDKLoginBehaviorSystemAccount.
Long story short, try:
let fbLoginManager = FBSDKLoginManager();
fbLoginManager.loginBehavior = FBSDKLoginBehaviorSystemAccount;
// call login method of choice here
How to implement login with FB using FBSDKLoginManager?
Add following line in applicationDidFinishLaunching
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
and add this method in 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];
}
Credit goes to FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES
Facebook login fails (always isCancelled) after upgrading to SDK 4.1
Thanks to Dheeraj and its answer to a similar question, I found the error in my calls. I just made the stupidest error in Swift. In the unlikely event someone as dumb as I am read this, here are the 3 calls in Swift that you should add in your AppDelegate.swift. They are tested and working:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Do what you have to do but at the end, instead of 'return true', put :
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
linkUserInBackground return succeeded as NO
I got my answer:
FBSDKLoginManager logInWithPublishPermissions always returns isCancelled=YES
"This can happen when your Facebook App doesn't have "publish_actions"
permission, or you're not using a test user."
ios Facebook Login button - doesn't change to Log out
so I started all over, and followed the instructions from the guide:
1.in the viewController.h file:
#import < FBSDKCoreKit/FBSDKCoreKit.h> //<-delete the space
#import < FBSDKLoginKit/FBSDKLoginKit.h>//<-delete the space
@interface ViewController : UIViewController<FBSDKLoginButtonDelegate>
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
2.in the viewController.m file:
-(void) viewDidLoad{
if ([FBSDKAccessToken currentAccessToken]) {
// User is logged in, do work such as go to next view controller.
}
self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
[self.view addSubview:loginButton];
}
and after that didn't work, I've found this thread that mentioned I also need to add few things to the AppDelegate didFinishLaunchingWithOptions :
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
and
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
and then it worked!
finally I had the Log in button changed to Log out!
Related Topics
Uiwebview and Safari Comparison
Create and Perform Segue Without Storyboards
Application Not Automatically Launching in Device and Getting Error on Xcode
Switching Viewcontrollers with Uisegmentedcontrol in iOS5
How to Detect That the App Is Running on a Jailbroken Device
Save and Retrieve Value via Keychain
Installing Ffmpeg iOS Libraries Armv7, Armv7S, I386 and Universal on MAC with 10.8
Decrease the Width of the Last Line in Multiline Uilabel
Changing View Controller When Segmented Control Changes
How to Calculate the Uilabel Height Dynamically
Storing Uicolor Object in Core Data
Have a Variable with Multiple Types in Swift
What Is MACh-O Type Should I Use It in My iOS Objective-C Project
How to Hide 'Back' Button on Navigation Bar on Iphone
How to Create Border in Uibutton
What Advantage(S) Does Dispatch_Sync Have Over @Synchronized
How Shouldchangecharactersinrange Works in Swift
How to Get Animated Polyline Route in Gmsmapview, So That It Move Along with Map When Map Is Moved