Reproduce
1. Run the following code in a simple classic project.
var win = Ti.UI.createWindow({
backgroundColor: "white",
});
// facebook
var fb = require('facebook');
fb.initialize();
fb.addEventListener('login', function(e) {
if (e.success) {
Ti.API.info('login from uid: '+e.uid+', name: '+ JSON.parse(e.data).name);
checkPermission();
}
else if (e.cancelled) {
alert('cancelled');
}
else {
alert(e.error);
}
});
// button to tigger facebook authorise and check the permission
var button = Ti.UI.createButton({
title:"Authorise and check the permission",
top: 100
});
button.addEventListener('click',function(e){
if (!fb.loggedIn) {
console.log("not logged yet.");
fb.authorize();
} else {
checkPermission();
}
});
win.add(button);
function checkPermission() {
if(fb.permissions.indexOf('publish_actions') < 0) {
Ti.API.info("No publish_action permission");
} else {
Ti.API.info("Do have publish_action permission");
}
}
win.open();
2. Click the button to login/authorise.
3. Then click it again to check permissions.
Problem.
App will cash if you click the button for several times.
Note
No any crash log in console.
Can you add
fb.initialize()
before using the module instance? Just some troubleshooting.I've put it into this sprint for further investigation. Is there a difference between main-thread enabled and disabled? The issue is definitely threading-related and I guess the problem is that we wait for the permissions [here](https://github.com/appcelerator-modules/ti.facebook/blob/master/ios/Classes/FacebookModule.m#L178) which can produce problems when being used in properties that need to return something immediately. I'll update this ticket as soon as I've tested it.
PR: https://github.com/appcelerator-modules/ti.facebook/pull/60 Ok, so here it what the PR does: - The getter was forced to run on the main-thread and wait for the result. That caused major problems, since the return value has not been retained. - I also found out that this was a known issue in the Facebook-SDK, so I updated it to the latest stable available - While I did that, I also found some memory-leaks across the share-dialogs which I fixed - I tested the change with both kroll- and main-thread and did a click-penetration with 20+ clicks and no crash (before: crash after 2-3 times visible) - Finally bumped the version of ti.facebook to 1.2.3
Pre-release: https://github.com/appcelerator-modules/ti.facebook/releases/tag/ios-5.2.3
[~hansknoechel] PR merged. Proceed to have the packaged Facebook module PR into titanium_mobile please.
PR (titanium_mobile/master): https://github.com/appcelerator/titanium_mobile/pull/8234 New ti.facebook iOS version 5.2.3 released.
Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.