2012-04-19 33 views
0

一個可能的解決方案是使用自定義網址:如何使兩個AIR IOS應用程序通信?

我按照following tutorial,然後進一步探討了在IOS兩個AIR應用程序的通信。 - 第一個應用程序使用自定義URI「fbMY_APP_ID」,如第一步所述,這可以由Safari調用。 - 第二個應用程序使用URLRequest和自定義URI與第一個應用程序進行通信。

我收到錯誤:「SecurityError:錯誤#2193:安全沙箱違規:navigateToURL:app:/secondApp.swf無法訪問tfbMY_APP_ID:// test」。

  1. 我在這種方法中遺漏了什麼嗎?有什麼辦法擺脫這個問題嗎?
  2. 除了使用自定義網址之外,還有其他方法嗎?

回答

1

據Adobe AIR的施加的安全沙箱,navigateURL僅限於衆所周知的協議,如http:,HTTPS :,短信:,電話:郵寄地址:,文件:,應用:,應用存儲: ,vipaccess:和connectpro :.您可以通過herehere找到更多信息。

解決問題的一種方法是利用html頁面作爲中間頁面,在該頁面中繼呼叫。

1

您可以從應用程序清單文件中像這樣(你可以添加多個協議)

<iPhone> 
... 
    <InfoAdditions> 
     <![CDATA[ 
      ... 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>thisIsSomeCustomAppProtocol</string> 
      </array> 
      ... 
      ]]> 
    </InfoAdditions> 
    ... 
</iPhone> 

添加自定義協議,並調用自定義協議是這樣的:

<a href="thisIsSomeCustomAppProtocol://SomeCustomDataString_goes_here&use_url_encoded_strings:">This will call the App with some parameters included (if need be)</a> 

或者使用navigateToURL(...)像這樣:

var _customURL_str:String  = "thisIsSomeCustomAppProtocol://SomeCustomDataString_goes_here&use_url_encoded_strings"; 
var _isProtocolAvailable:Boolean= URLUtils.instance.canOpenUrl(_customURL_str); 
// 
if(_isProtocolAvailable) 
{ 
    navigateToURL(new URLRequest(_customURL_str)); 
} 

要監聽呼叫和實際處理數據tha T的傳遞,這樣做:

NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE,_invokeHandler); 

事件處理程序將處理這樣的數據:

private function onInvoke(e:InvokeEvent):void 
{ 
    //... 
    var _queryString:String = e.arguments[0] ? e.arguments[0] : ""; 
    // 
    if(_queryString.length > 0){ 
     //handle the incomming data string 
    }else{ 
     //no extra data string was sent 
    } 
    //... 
} 

希望幫助

乾杯:

-Nick

相關問題