Closed enchev closed 9 years ago
From @EddyVerbruggen on May 20, 2015 9:35
Did you setup a valid Fb URL scheme in your .plist file? It looks like that's what the stacktrace is referring to.
For instance, the Cordova plugin adds it for you but with {N}, currently, you need to do it yourself.
From @duongnhatduy on May 20, 2015 9:37
Yeah I forgot that, I will try it now.
From @duongnhatduy on May 20, 2015 10:20
yes, it works. Thanks
From @duongnhatduy on May 20, 2015 12:25
Facebook requires to edit App Delegate: https://developers.facebook.com/docs/ios/getting-started#startcoding. We can do it in Cordova, how can we do it in Nativescript? At the moment, I always get Cancelled result when handling login callback from browser.
@duongnhatduy
Our application module defines custom AppDelegate
called TNSAppDelegate
. When the system calls TNSAppDelegate
methods (e.g. application:didFinishLaunchingWithOptions:
) it calls our custom event handler (e.g. onResume
, onLaunch
). You can read more about these events here: https://docs.nativescript.org/application-management#use-application-callbacks. You can execute custom logic by setting custom function on these events:
var application = require("application");
application.mainModule = "main-page";
application.cssFile = "./app.css";
application.onResume = function() {
FBSDKAppEvents.activateApp();
}
application.start();
For iOS, onLaunch
function is called from applicationDidFinishLaunchingWithOptions method of our TNSAppDelegate
. As you can see in source code, onLaunch
is called without arguments, so from there you have no access to launchOptions
parameter. A temporary solution is to edit the application module source code and pass all the needed arguments to the respective event handlers. You can keep an eye on this issue https://github.com/NativeScript/NativeScript/issues/233 and its progress. Feel free to contribute to our repo if come up with an implemented solution.
Anyone willing to share working FB login with NS or perhaps create a module for it?
+1, need to get Facebook Login working for my app but no idea how to do it!
/// <reference path="./tns_modules/application/application.d.ts"/>
import {mainModule, cssFile, start, onLaunch, onResume, onOpenURL} from "application";
mainModule = "launchpage/launch-page";
cssFile = "./app.css";
// Init Facebook SDK login
onLaunch = function(application, launchOptions) {
FBSDKApplicationDelegate.sharedInstance().applicationDidFinishLaunchingWithOptions(null, null);
};
onResume = function() {
FBSDKAppEvents.activateApp();
};
NSNotificationCenter.defaultCenter().addObserverForNameObjectQueueUsingBlock(
"com.telerik.TLKApplicationOpenURL",
null,
null,
function(note: NSNotification, a2) {
var TLKApplicationOpenURL = note.userInfo;
var url = TLKApplicationOpenURL.objectForKey("TLKApplicationOpenURL");
var application = TLKApplicationOpenURL.objectForKey("TLKApplication");
console.log("noti", TLKApplicationOpenURL, url, application);
FBSDKApplicationDelegate.sharedInstance().applicationOpenURLSourceApplicationAnnotation(
application,
url,
"com.apple.mobilesafari",
null
);
}
);
start();
Here is my login handler
export function facebookLoginHandler() {
var fbLoginMng: FBSDKLoginManager = new FBSDKLoginManager();
fbLoginMng.logInWithReadPermissionsHandler([], function(result: FBSDKLoginManagerLoginResult, error: NSError) {
console.log("ERRROR", error);
console.log("RESULT Token", result.token);
console.log("GRented", result.grantedPermissions);
console.log("Deny", result.declinedPermissions);
console.log("Cancel", result.isCancelled);
});
}
I managed to get it working. However, I always get response isCancelled as true.
Would it be possible to share a sample app? My NS build is just failing with ld: framework not found FBSDKCoreKit
Did you drag FBSDKLoginKit.framework and FBSDKCoreKit.framework to your ios project?
I got it working in the end, but manually dragging the frameworks into the project didn't work, had to run tns library add ...
, and then also had to add CoreGraphics in the Xcode project.
Unfortunately it now only runs on the emulator, not the device. the tns deploy
step fails at VerifyingApplication
, and Xcode says "The application does not have a valid signature".
yea, now I remember I did run tns library add... as well
Hi @dbbk,
From what I've seen when this happens, it is usually a code-signing error. Can you try to deploy to device using Xcode? Also, you may have to allow your device to be used for development in Xcode Organizer:
Run
DevToolsSecurity -enable
I've had no problems with deploying to device until adding the Facebook SDK. I even recreated the project from scratch and could deploy the Hello World sample fine, but it stopped working once the SDK library was added.
I just updated nativescript cli from 1.0 to 1.1 and encountered same problem. I had to add CoreGraphics and deploying to device fails at VerifyingApplication
has anyone managed to solve the problem?
From @duongnhatduy on May 20, 2015 9:28
I tried to use iOS SDK, but it crash the whole app without recovering:
log
Copied from original issue: NativeScript/NativeScript#192