Search code examples
iosfacebookappcelerator

Appcelerator Facebook Module Authorize() Does Not Present Login Dialog on IOS


I'm using version 5.0.1 of appcelerator's facebook module with their 5.2.1ga sdk. I cannot get the module to present a facebook login dialog for sharing. Here's my code:

  var FacebookPublic = require("FacebookPublic");  
  var fb = require('facebook');            
  // Test 
  // fb.setLoginBehavior(fb.LOGIN_BEHAVIOR_WEB );
  //  fb.permissions = ['email'];
  //  fb.permissions = ['read_stream','publish_actions'];
  //  fb.initialize(); 
  fb.authorize();               
  if ( fb.getLoggedIn() == false )
  {
     alert('Error Logging Into Facebook');
     return;                      
  }

My code does not log any errors and just blows by the fb.authorize() to the alert('Error Logging Into Facebook') statement. I have tried the various log in behaviours (see the commented section in my code)

Here's the plist from my tiapp.xml

 <key>CFBundleURLTypes</key>
            <array>
                <dict>
                    <key>CFBundleURLSchemes</key>
                    <array>
                        <string>fbXXX</string>
                    </array>
                </dict>
            </array>
            <key>FacebookAppID</key>
            <string>XXX</string>
            <key>FacebookDisplayName</key>
            <string>MYFACEBOOKAPP</string>
            <key>LSApplicationQueriesSchemes</key>
            <array>
                <string>fbapi</string>
                <string>fb-messenger-api</string>
                <string>fbauth2</string>
                <string>fbshareextension</string>
                <string>fbapi20130214</string>
                <string>fbapi20130410</string>
                <string>fbapi20130702</string>
                <string>fbapi20131010</string>
                <string>fbapi20131219</string>
                <string>fbapi20140410</string>
                <string>fbapi20140116</string>
                <string>fbapi20150313</string>
                <string>fbapi20150629</string>
                <string>fbauth</string>
                <string>fb-messenger-api20140430</string>
            </array>

I have configured my facebook developer account for IOS with my bundleId. The same code works without issues in my android app. Does anyone have any ideas on how to get this to work?

Thanks


Solution

  •     var fb = require('facebook');
         fb.permissions = [FACEBOOK_APP_PERMISSIONS];
         fb.initialize(); // <-- YOU NEED INITIALIZE MODULE
         //for get error or success add listener
         fb.addEventListener('login', function(e) {
            if (e.success) {
                alert('login from uid: '+e.uid+', name: '+  JSON.parse(e.data).name);
                label.text = 'Logged In = ' + fb.loggedIn;
            }
            else if (e.cancelled) {
                // user cancelled
                alert('cancelled');
            }
            else {
                alert(e.error);
            }
         });
         fb.authorize();