【问题标题】:Titanium IPhone module钛 iPhone 模组
【发布时间】:2013-03-06 15:13:17
【问题描述】:

这是我第一次为 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这样的委托。

我把它放在startup函数中如下:

-(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.}

如有任何帮助,我们将不胜感激。提前致谢。

【问题讨论】:

    标签: xcode module delegates google-analytics titanium-mobile


    【解决方案1】:

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

    ENSURE_UI_THREAD(functionName,args);

    ENSURE_UI_THREAD_0_ARGS
    

    更多类似方法请查看iOS Module Development Guide

    【讨论】:

    • @senthil: 很高兴:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    相关资源
    最近更新 更多