在我的LoginViewController中,我实现了FBSDKLoginButtonDelegate并导入了FBSDKLoginKit和FBSDKCoreKit。我在viewDidLoad中的代码如下所示:
//setting up facebook login button
var facebookLogin = FBSDKLoginButton()
//want this button to conform to this protocol
facebookLogin.delegate = self
facebookLogin.readPermissions = ["public_profile", "email", "user_friends"]
facebookLogin.frame = CGRectMake(20, 359, 335, 30)
self.view.addSubview(facebookLogin)
Run Code Online (Sandbox Code Playgroud)
这是按钮的代码:
public func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult
result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if error != nil {
print(error.localizedDescription)
return
} else {
print("No error")
self.performSegueWithIdentifier("loginToFeed", sender: self)
}
}
Run Code Online (Sandbox Code Playgroud)
登录后,页面停留在此白屏,而不是返回到应用程序。因此,我继续按“完成”以手动返回到应用程序,并且控制台打印出没有错误,并继续进行到提要。现在,下一个有趣的部分是尽管登录时没有错误,但我仍未登录。你知道这是怎么回事吗?我错过了一步吗?
在关闭网络请求时,我使用私有并发队列将对象插入到核心数据中,并在私有上下文中调用“执行”时发生崩溃。
控制台中的崩溃消息:
libc++abi.dylib:以未捕获的 NSException 类型异常终止
导致崩溃的代码:
API.sync(onlyMe, syncToken: syncToken) { success, syncResponse in
CoreDataUtils.privateContext.perform { // crashes on this line
....
}
}
Run Code Online (Sandbox Code Playgroud)
我的核心数据堆栈(不幸的是,目前位于 AppDelegate 而不是 CoreDataStack 类中):
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// …Run Code Online (Sandbox Code Playgroud) 用户登录后,我将尝试提供静态文件。我应用了此处找到的答案,但实施起来遇到困难。
登录后,我在routes.js中有这样的内容:
app.post('/', function(req, res){
AM.manualLogin(req.body['user'], req.body['pass'], function(e, o){
if (!o){
res.status(400).send(e);
} else {
req.session.user = o;
if (req.body['remember-me'] == 'true'){
res.cookie('user', o.user, { maxAge: 900000 });
res.cookie('pass', o.pass, { maxAge: 900000 });
}
console.log(req.session);
res.status(200).send(o);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我在请求的会话中设置用户。
在 app.js 里面我有:
var http = require('http');
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var errorHandler = require('errorhandler');
var cookieParser = require('cookie-parser');
var MongoStore = require('connect-mongo')(session);
var app = express();
app.locals.pretty = …Run Code Online (Sandbox Code Playgroud)