2014-04-18 108 views
0

我在我的服務器中有用於測試的URL和用於生產的另一個URL。檢測應用程序是否臨時

在我的代碼,某些時候,我這樣做:

#ifdef DEBUG 
    static NSString * const url = "http://sandbox.myserver.com"; 
#else 
    static NSString * const url = "http://live.myserver.com"; 
#endif 

這工作得很好,當我調試的Xcode的應用程序,但如果我把我的應用程序的臨時版本的beta測試將會失敗。臨時應用程序將使用生產URL而不是沙箱。

做這個測試的正確方法是什麼?

回答

1

簡稱:

var data = String($.NSString.stringWithContentsOfFileEncodingError($.NSBundle.mainBundle.pathForResourceOfType('embedded', 'mobileprovision'), $.NSISOLatin1StringEncoding, null)); 
data = data.slice(data.indexOf('<plist')); 
data = data.slice(0, data.indexOf('</plist>')+8); 
data = $.NSString.stringWithString(data).dataUsingEncoding($.NSISOLatin1StringEncoding); 
var mobileProvision = $.NSPropertyListSerialization.propertyListWithDataOptionsFormatError(data, $.NSPropertyListImmutable, null, null); 
if (mobileProvision.valueForKey('ProvisionedDevices')) { 
    res.debug = 'adhoc'; 
} else { 
    res.debug = false; 
} 
+0

感謝!!!!!!!!! – SpaceDog

相關問題