1

我想在我的應用程序中獲取GA。我試着這樣做:在Xcode5 SDK 3.03中編譯時添加Google Analytics(分析)鏈接器錯誤

我用這個谷歌Analytics(分析)SDK適用於iOS 3.0版(測試版) - https://developers.google.com/analytics/devguides/collection/ios/v3/

我已經按照文檔的所有步驟。 也已經嘗試過Linker errors when trying to install new Google Analytics 3.0 Beta

enter image description here

在我AppDelegate.h

#import <UIKit/UIKit.h> 
#import "GAI.h" 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property(nonatomic, strong) id<GAITracker> tracker; 
@property (strong, nonatomic) UIWindow *window; 

@end 

在我AppDelegate.m

#import "AppDelegate.h" 
#import "GAI.h" 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [GAI sharedInstance].trackUncaughtExceptions = YES; 

    // Optional: set Google Analytics dispatch interval to e.g. 20 seconds. 
    [GAI sharedInstance].dispatchInterval = 20; 

    // Optional: set Logger to VERBOSE for debug information. 
    [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose]; 

    // Initialize tracker. 
    id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-47246605-1"]; 

    [GAI sharedInstance].optOut = YES; 
    [GAI sharedInstance].trackUncaughtExceptions = YES; 
    [GAI sharedInstance].dispatchInterval = 0; 

    return YES; 
} 

ViewController.h

#import <UIKit/UIKit.h> 
#import "GAI.h" 
#import "GAITrackedViewController.h" 

@interface ViewController : GAITrackedViewController 
@end 

ViewController.m

#import "ViewController.h" 
#import "GAI.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.screenName = @"Home Screen"; 

} 

鏈接,我的項目的測試:https://www.dropbox.com/s/j3ufrv55xym82nc/TesteAnalytics.zip

+0

如何確定您錯過了哪個框架:1)查看「未定義符號」部分中的名稱; 2)谷歌他們(沒有_OBJC_CLASS _ $ _部分); 3)點擊該類的Apple文檔鏈接並閱讀框架名稱。 – Kreiri

回答

0

谷歌分析使用的CoreData.framework,和鏈接器無法找到它。 (NSManagedEntity,NSManagedContext等都是CoreData類)

您是否將該框架添加到您的項目中?

+0

我忘了這個,謝謝。 現在我沒有更多的錯誤,但是當我進入analytcs實時儀表板時,他不計數。 –

+0

我很高興它幫助:)如果這個答案解決了您的問題,請將其標記爲接受的答案。 –

0

我改變了這一點,現在就開始工作。

#import <CoreData/CoreData.h> 
#import "AppDelegate.h" 
#import "GAI.h" 

@implementation AppDelegate 

static NSString *const kTrackingId = @"UA-47244310-1"; 
static NSString *const kAllowTracking = @"allowTracking"; 

- (void)applicationDidBecomeActive:(UIApplication *)application { 
    [GAI sharedInstance].optOut = ![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    NSDictionary *appDefaults = @{kAllowTracking: @(YES)}; 
    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; 
    // User must be able to opt out of tracking 
    [GAI sharedInstance].optOut = 
![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking]; 
    // Initialize Google Analytics with a 120-second dispatch interval. There is a 
    // tradeoff between battery usage and timely dispatch. 
    [GAI sharedInstance].dispatchInterval = 120; 
    [GAI sharedInstance].trackUncaughtExceptions = YES; 
    self.tracker = [[GAI sharedInstance] trackerWithName:@"TesteDelegate" 
              trackingId:kTrackingId]; 

    return YES; 
} 
相關問題