Quentin Bernet
Quentin Bernet

Reputation: 43

Get back to mobile application after leaving it with Appcelerator Titanium

I was wondering if there were any ways to get back into my mobile application after leaving it.

For example, if i redirect the user into a webpage, how can i redirect the user into the application once the page's request has been finished? Moreover, i'd like to redirect the user to the app conserving some parameters given by the current webpage..

Second example, i guess facebook does sthg like that when a user uses the facebook signin button as he's directly redirected to the facebook web page and then goes back to the app with the facebook answer parameters.

I'm currently using Titanium with Alloy framework and Appcelerator Studio.

Hoping anyone of you has an answer,

Best regards,

Quentin

Upvotes: 0

Views: 139

Answers (2)

Sebastian
Sebastian

Reputation: 625

I think what you want to do is switching between apps: Your app -> Safari -> Back to your app via link

You have to define an url scheme in your tiapp.xml in the ios -> plist -> dict section

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

With that, you can make a link in html like

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

I've not tried that code, but that's the way it should work

Upvotes: 2

Skoempie
Skoempie

Reputation: 1181

I'm not sure it that's possible since you technically leave your application. I used a WebView to render a HTML page which fires an event(with a certain payload) when a certain action is completed. The listener in my controller then catches this event and handles the payload from there.

Create a new file in your app->assets folder and name it for example yoursite.html.

Paste the following code in it:

<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>

Then add the following code to your controller:

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();

Tip: Global event listeners are not good for the performance of your app. If the user has the see the webview only once(single action like a login) then I suggest you using the following code:

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();

Upvotes: 1

Related Questions