使用 Appcelerator Titanium 离开后返回移动应用程序

Get back to mobile application after leaving it with Appcelerator Titanium

我想知道是否有任何方法可以在离开后返回我的移动应用程序。

例如,如果我将用户重定向到网页,那么在页面请求完成后如何将用户重定向到应用程序? 此外,我想将用户重定向到保留当前网页给出的一些参数的应用程序。

第二个例子,我猜当用户使用 facebook 登录按钮时 facebook 会做一些事情,因为他被直接重定向到 facebook 网页,然后返回到带有 facebook 答案参数的应用程序。

我目前正在使用带有 Alloy 框架和 Appcelerator Studio 的 Titanium。

希望你们中的任何人都能得到答案,

此致,

昆汀

我不确定这是否可行,因为您在技术上已经离开了您的申请。我使用 WebView 呈现一个 HTML 页面,当某个操作完成时,该页面会触发一个事件(具有特定的有效负载)。然后我的控制器中的侦听器捕获此事件并从那里处理有效负载。

在您的 app->assets 文件夹中创建一个新文件并将其命名为例如 yoursite.html。

在其中粘贴以下代码:

<html>
  <head>
    <title>Test</title>
    <script type="text/javascript">
      window.onload = function() 
      {
        Ti.App.fireEvent('your_event', { 'message': 'Hello World!' });            
      };
    </script>
  </head>
  <body>
  </body>
</html>

然后将以下代码添加到您的控制器中:

var win = Ti.UI.createWindow();         

Ti.App.addEventListener('your_event', function(e)
{
    alert(e.message);
});

win.add(Ti.UI.createWebView({ url: '/yoursite.html' }));

win.open();

提示:全局事件侦听器不利于应用的性能。如果用户只看到一次 webview(像登录这样的单一操作),那么我建议你使用以下代码:

var win = Ti.UI.createWindow();         

var setWebViewEventHandler = function(e)
{
    this.removeEventListener('your_event', setWebViewEventHandler);

    alert(e.message);
}   

Ti.App.addEventListener('your_event', setWebViewEventHandler);

win.add(Ti.UI.createWebView({ url: '/yoursite.html' }));

win.open();

我想你想要做的是在应用程序之间切换:你的应用程序 -> Safari -> 通过 link

返回你的应用程序

您必须在 ios -> plist -> dict 部分 tiapp.xml 中定义一个 url 方案

<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.your.app</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>appurlscheme</string>
        </array>
    </dict>
</array>

这样,您就可以在 html 中制作一个 link 就像

<a href="appurlscheme://">Back to your app</a>

我没有尝试过该代码,但它应该是这样工作的