这就是我在加载网站时所说的:
(function($){})(window.jQuery);
$(document).ready(function () {
window.addEventListener('cloudkitloaded', function() {
CloudKit.configure({
containers: [{
containerIdentifier: 'iCloud.pl.blueworld.fieldservice',
apiToken: 'fc363369412ad6c99020e7e0ed3e2be121008e34534cff7debe1f4f7f829d152',
environment: 'production'
}]
});
var container = CloudKit.getDefaultContainer();
var privateDB = container.privateCloudDatabase;
this.gotoAuthenticatedState = function(userInfo) {
if(userInfo.isDiscoverable) {
//success
} else {
//failure
}
container
.whenUserSignsOut()
.then(this.gotoUnauthenticatedState);
};
this.gotoUnauthenticatedState = function(error) {
//do something of sign out
container
.whenUserSignsIn()
.then(this.gotoAuthenticatedState)
.catch(this.gotoUnauthenticatedState);
};
container.setUpAuth().then(function(userInfo) {
if(userInfo) {
this.gotoAuthenticatedState(userInfo);
} else {
this.gotoUnauthenticatedState();
}
});
});
});
当我成功登录时,会出现正确的按钮:
但是每次刷新页面时,此按钮都会更改:
在用户手动注销之前如何保持会话和获取记录的可能性?
如何检查是否存在当前会话(用户已经通过身份验证)并使用它?