0

我的 Titanium 应用程序有问题……我在互联网上查找了一些教程,并在 facebook 模块上查找了 Appcelerator,更具体地说是登录/注销。我试图在当天调整这个错误,但我不能以任何方式......我提供我的项目以供下载,如果你可以下载和测试会有所帮助!

我正在尝试登录android,但该应用程序也必须适用于ios ...如果您能告诉我我如何为我做两个或指出真正有效的项目...。

下载我的项目:http ://we.tl/hqvEpb2aeG

在我的文件下面:

登录.js

//Abir Fluxo de Caixa
function openFluxoDeCaixa(){
    var winFluxo = Alloy.createController('fluxo').getView();
    winFluxo.open();
}

fb.addEventListener('login', fbLogin);

$.btnLoginFacebook.addEventListener('click',function(e){
    fb.authorize();
});


function fbLogin(e){

    fb.removeEventListener('login', fbLogin);

    if(e.success){

        var fbdata = {};
        fbdata = JSON.parse(e.data);

        var uFoto = 'https://graph.facebook.com/' + fbdata.id + '/picture?width=300&height=300';
        var uNome = fbdata.name;

        var slipName = uNome.split(" ");

        Ti.App.Properties.setString('logged', 'true');
        Ti.App.Properties.setString('foto', uFoto);
        Ti.App.Properties.setString('nome', slipName[0]);

        openFluxoDeCaixa();
    } 
}


$.windowLogin.open();

合金.js

var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();

if(OS_ANDROID){
    $.windowLogin.fbProxy = fb.createActivityWorker({lifecycleContainer: $.windowLogin});
}



Alloy.Globals.LocalFunctions = {
    setLogin : function setLogin(uId, uNome, uPlataforma){

    var getLogin = Titanium.Network.createHTTPClient();
        getLogin.open("POST","http://www.skrow.cc/ws-qia/controller.php");

        var params = {
            action: 'addLogin',
            id: uId,
            nome: uNome,
            plataforma: uPlataforma
        };

        getLogin.send(params);
    }
};

TiApp.xml

<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
    <id>br.com.queroinvestiragora</id>
    <name>Quero Investir Agora</name>
    <version>1.0</version>
    <publisher>silviosampaio</publisher>
    <url>http://www.queroinvestiragora.com.br</url>
    <description>undefined</description>
    <copyright>2015 by silviosampaio</copyright>
    <icon>appicon.png</icon>
    <fullscreen>false</fullscreen>
    <navbar-hidden>false</navbar-hidden>
    <analytics>true</analytics>
    <guid>284edc0c-c599-4cae-9444-721cd3d22937</guid>
    <property name="ti.ui.defaultunit" type="string">dp</property>
    <ios>
        <plist>
            <dict>
                <key>UISupportedInterfaceOrientations~iphone</key>
                <array>
                    <string>UIInterfaceOrientationPortrait</string>
                </array>
                <key>UISupportedInterfaceOrientations~ipad</key>
                <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
                </array>
                <key>UIRequiresPersistentWiFi</key>
                <false/>
                <key>UIPrerenderedIcon</key>
                <false/>
                <key>UIStatusBarHidden</key>
                <false/>
                <key>UIStatusBarStyle</key>
                <string>UIStatusBarStyleDefault</string>
                <key>CFBundleURLTypes</key>
                <array>
                    <dict>
                        <key>CFBundleURLName</key>
                        <string>com.appcelerator.kitchensink</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                            <string>kitchensink</string>
                            <string>936940282991759</string>
                        </array>
                    </dict>
                </array>
            </dict>
        </plist>
    </ios>
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application android:theme="@style/Theme.NoActionBar">
                <activity android:label="@string/app_name"
                    android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
                <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
            </application>
        </manifest>
    </android>
    <mobileweb>
        <precache/>
        <splash>
            <enabled>true</enabled>
            <inline-css-images>true</inline-css-images>
        </splash>
        <theme>default</theme>
    </mobileweb>
    <modules>
        <module platform="commonjs">ti.cloud</module>
        <module platform="android" version="3.0.3">facebook</module>
        <module platform="iphone" version="3.2.0">facebook</module>
    </modules>
    <deployment-targets>
        <target device="android">true</target>
        <target device="blackberry">false</target>
        <target device="ipad">false</target>
        <target device="iphone">true</target>
        <target device="mobileweb">false</target>
    </deployment-targets>
    <sdk-version>3.5.1.GA</sdk-version>
    <plugins>
        <plugin version="1.0">ti.alloy</plugin>
    </plugins>
    <property name="appc-app-id" type="string">55ec85b523ec2d9730087189</property>
    <property name="acs-authbase-url-development" type="string">https://secure-identity.cloud.appcelerator.com</property>
    <property name="acs-base-url-development" type="string">https://api.cloud.appcelerator.com</property>
    <property name="acs-oauth-secret-development" type="string">0VlBf7xO3Z3aWr2ISM6BXr2vxQH8OPaU</property>
    <property name="acs-oauth-key-development" type="string">T8j8E5AOcEyUGOPtSZWaA4ygJLpi0pYL</property>
    <property name="acs-api-key-development" type="string">5p3UAhCmk7I3H9lYzip5Wb97H0h9I38V</property>
    <property name="acs-username-development" type="string">appc_app_user_dev</property>
    <property name="acs-password-development" type="string">fUoxkjYTGqxoE8ZTJ0</property>
    <property name="acs-authbase-url-production" type="string">https://secure-identity.cloud.appcelerator.com</property>
    <property name="acs-base-url-production" type="string">https://api.cloud.appcelerator.com</property>
    <property name="acs-oauth-secret-production" type="string">2JHJ4oZ4V0Ch5Gvy3GAnEkY4stnycUYn</property>
    <property name="acs-oauth-key-production" type="string">UTUK7lzz2Vuq54fSAErTk4NaN3kghPOJ</property>
    <property name="acs-api-key-production" type="string">3xGYGFJQAYXBK4quHslbKCfBtgAcCgXg</property>
    <property name="acs-username-production" type="string">appc_app_user</property>
    <property name="acs-password-production" type="string">rDD4YG0qQxtmdXg0yM</property>
    <property name="appc-org-id" type="string">100026191</property>
    <property name="appc-creator-user-id" type="string">baea2ab2-d377-4f02-aa1b-6b4553ffe12d</property>
</ti:app>
4

1 回答 1

1

合金.js 总是在您的应用程序启动时执行,但您在其中创建的变量默认情况下无法从其他控制器访问。

您需要使您的 facebook 模块在全局范围内可访问,以便在alloy.js 之外访问它,您可以通过更改alloy.js 中的以下行来做到这一点:

var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();

至:

Alloy.Globals.fb = require('facebook');
Alloy.Globals.fb.permissions = ['public_profile', 'read_stream'];
Alloy.Globals.fb.appid = 172237596444060;
Alloy.Globals.fb.forceDialogAuth = false;

在 login.js 中,您还需要在调用 fb.initialize() 之前设置成功登录 facebook 的回调函数 例如:

Alloy.Globals.fb.addEventListener('login', fbLogin);

此外,您必须在尝试调用 fb.initialize() 或 fb.authorize()之前设置登录/注销功能,因此您需要将 fb.initialize() 移动到 login.js 或将其从alloy.js 中删除,因为您已经在调用 fb.authorize()。

于 2015-10-08T21:51:40.383 回答