Passing app arguments via InvokeEvent or BrowserInvokeEvent in AIR for IOS doesn't work
Copy link to clipboard
Copied
Just figured I'd let everyone know that if you thought it'd be cool to let your IOS users launch your app from a link in a browser and that it would be cool to encode parameters in that URL to be passed into your app, you're out of luck. When you add a listener to your app like...
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
or..
NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE, onBrowserInvoke);
It doesn't fire on an IOS device, so there's no way to get the parameters out of the arguments property.
The app does indeed fire from a browser if you set up your custom URL scheme properly in your app.xml file. Framework just doesn't fire the handler function for the registered invoke listener. The parameter retrieval code at the link below, therefore, doesn't work on an IOS device.
http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications/
Copy link to clipboard
Copied
Sorry, I must have done it wrong, because I've successfully retrieved
URL parameters within an AIR iOS app that was launched with a custom URI
scheme from a website on the device.
Posting code shortly...
iBrent
Copy link to clipboard
Copied
Awesome. Desperate to see that. Holding up app submission at the moment.
Copy link to clipboard
Copied
Did you get anywhere with this? I'm having the same issue.
Thanks.
Copy link to clipboard
Copied
I had a reference to an unititialised variable which caused the handler to silently fail, but the app to continue. Android actually managed to work passed this issue, perhaps recalling the handler at a later point in the execution cycle, but either way, once I fixed the issue then parameter handling on iOS works.
Copy link to clipboard
Copied
iBr3nt's note said "posting code shortly". Have you had a chance to do that? I'm not seeing it here.
I'm using this code http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications/ and it definitely does not work. The handler simply does not fire so there is no way to pull the parameter values into the app.
Thanks
Copy link to clipboard
Copied
The below works for me based on a url of the form "my.app.scheme://arg1&arg2"
...
preinitialize="application_preinitializeHandler(event)"
...
protected function application_preinitializeHandler(event:FlexEvent):void
{
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
}
private function onInvoke(event:InvokeEvent):void
{
if(event.arguments[0]!=null) {
arg = event.arguments[0];
arg = arg.substr(arg.indexOf("//") + 2);
}
}
...
You will also have to make sure you have registered your custom schema (as used in your launch URLs) in your -app.xml e.g.
...
android
...
<application>
<activity>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="my.app.scheme"/>
</intent-filter>
</activity>
</application>
...
iOS
...
<key>CFBundleURLSchemes</key>
<array>
<string>my.app.scheme</string
</array>
...
Copy link to clipboard
Copied
No longer works on Android!
I can launch an AIR app from Native code using a normal URL tied to a web site URL but defining a custom scheme does not work on Android devices running 4.0 or later!
I launch my AIR app like this:
String url = "http://mobile.telmate.com/videostreaming?parmOne=522";
Intent intent = new Intent(Intent.ACTION_VIEW, Url.parse(url));
startActivity(intent);
This launches my Adobe air app fine which has this added to its Application.xml file
<application android:enabled="true">
<activity
android:exported="true"
android:excludeFromRecents="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="http" android:host="mobile.telmate.com" android:pathPrefix="/videostreaming"/>
</intent-filter>
</activity>
</application>
I trap the InvokeEvent in the preInitialize in my AIR mobile app but I always get the Reason property set to "standard" for some reason.
Does anyone know why?
I running AIR 3.5.8090 on Android 4.2
Copy link to clipboard
Copied
thanks! this does really work
Copy link to clipboard
Copied
We had a similar problem:
in the invoke-handler we checked for the InvokeEvent.reason to be 'openUrl',
which worked when building the ipa with fast packaging (using IntelliJ IDEA)
but din't work when building with packaging set to 'ipa-ad-hoc' using ANT script (which takes about half an hour for our app).
Solution: in the 'ipa-ad-hoc' mode the InvokeEvent.reason is always 'standard'
in the 'openUrl' case InvokeEvent.arguments contains the url as the first element
when the app is just started via app-icon the InvokeEvent.arguments is null or an empty list.
Hope that helps anybody who is trying to get this working.
