2013-03-06 59 views
1

這是我第一次爲iPhone開發鈦模塊。我正在爲iPhone構建Google Analytics模塊。鈦iPhone模塊

如果我要使用XCode實施Google Analytics,則可以使用didFinishLaunchingWithOptions委託。下面是這個例子:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions 
    { 
     // Override point for customization after application launch. 
     id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXXXXXX-X"]; 
      return YES; 
    } 

我試過了,它完全適合我。

說到鈦模塊,我認爲沒有委託,如didFinishLaunchingWithOptions。

我把它放在下面的啓動功能:

-(void)startup 
{ 
    // this method is called when the module is first loaded 
    // you *must* call the superclass 
    [super startup]; 
     id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-38803610-1"]; 
    NSLog(@"[INFO] %@ loaded",self); 
} 

,但是當我執行我的應用程序如下圖所示:

var mod = require("com.mymodule") 
Ti.API.log("The module: " + mod) 

我收到以下錯誤:

: Dispatcher initialization failed: Error Domain=com.google.analytics.error Code=1 "Dispatcher must be initialized on main thread." UserInfo=0xb3d1270 {NSLocalizedDescription=Dispatcher must be initialized on main thread.} 

任何幫助將appriciated。提前致謝。

回答

2

您需要在主線程中執行UI任務。你可以這樣做,使用:

ENSURE_UI_THREAD(functionName,args);

ENSURE_UI_THREAD_0_ARGS 

請檢查該iOS Module Development Guide更多的類似的方法

+0

嘿,非常感謝。得到它的工作... – senthil 2013-03-07 07:52:44

+0

@senthil:高興:) – 2013-03-07 07:55:56