Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Closing a window after Facebook login is authorized

$
0
0

I'm trying to implement the Titanium Facebook module into my app, and I've got it working to some degree, but I'm having a few issues.

What I'm trying to achieve is...

  1. App launches to a window with a logo and Facebook login button
  2. User taps login button to authorise with Facebook
  3. If authorised, the window closes and shows the app beneath

I've had some success, but getting it all together, I'm really struggling!

Can anyone who'd had some experience with this module shed any light on what could be going wrong?

I'm running this on iOS 8.1 in Titanium 3.4.0 in Classic (not Alloy).

Here is my trimmed down code....

// Set the animations
var animateDown = Titanium.UI.createAnimation();
    animateDown.bottom = -800; 
    animateDown.duration = 5000;
 
// Holding window for login buttons
var loginWindow = Titanium.UI.createWindow({  
    title:'Login',
    backgroundColor:'#000',
    barColor:'#000',
    tintColor:'#00c0ff'
});
 
var fb = require('facebook');
// Initial permissions must exclude offline and write priviledges
fb.appid = 'xxxxx';
fb.permissions = ['public_profile', 'user_friends', 'email'];
 
// This property needs to be false to use the built-in iOS 6 login
fb.forceDialogAuth = false;
 
fb.addEventListener('login', function(e) {
    if (e.success) {
        alert('Logged In');
        launchApp(); // my function to animate the window away
    } else if (e.error) {
        alert(e.error);
    } else if (e.cancelled) {
        alert("Canceled");
    }
});
 
// Add the button.  Note that it doesn't need a click event listener.
loginWindow.add(fb.createLoginButton({
    bottom : 100,
    style : fb.BUTTON_STYLE_WIDE
}));
 
loginWindow.open();
 
// create tab group
var tabGroup = Titanium.UI.createTabGroup({
    tabsBackgroundColor:'#000',
    tabsTintColor:'#00c0ff'
});
 
///////// TAB SETUP GOES IN HERE
 
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.addTab(tab3); 
tabGroup.addTab(tab4); 
tabGroup.addTab(tab5);
 
// after login we can then hide the window and open the tab group
var launchApp = function() {
 
    // hide the window
    loginWindow.close(animateDown);
 
    // open tab group
    tabGroup.open();
 
};
I also need to detect if they have already authorised the app (returning users) and hide loginWindow so they don't need to login every time.

Any ideas how I can achieve this?

I already check to see if the user is logged in, but it seems to want to ignore that and just launch the launchApp() function anyway.

if (!fb.loggedIn) {
    launchApp();  
}
At the moment, with this code, if I tap the Facebook login button, iOS pops a Facebook system alert to ask me if i'd like to authorise the app to access my friends lists etc. So something is happening!

I'm just trying to avoid users being able to access the app without having logged in.

I must be doing something really stupid!

Simon


Viewing all articles
Browse latest Browse all 8068

Trending Articles