1

这是我第一次为 iPhone 开发钛金属模块。我正在为 iPhone 构建 Google Analytics 模块。

如果我要使用 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;
  }

我试过了,对我来说效果很好。

说到Titanium Module,我认为没有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.}

任何帮助都将不胜感激。提前致谢。

4

1 回答 1

2

您需要在主线程中执行 UI 任务。你可以这样做:

ENSURE_UI_THREAD(functionName,args);

ENSURE_UI_THREAD_0_ARGS

有关更多类似方法,请查看此iOS 模块开发指南

于 2013-03-07T05:48:41.263 回答