it-swarm.com.de

Der Wert des Typs "NSMutableDictionary" kann nicht in den Typ "[NSObject: AnyObject]" in Zwang für Google ios Analytics konvertiert werden

Ich möchte Google Analytics ios in mein Projekt einfügen, aber ich habe einige Probleme, als ich versuchte, ihren Code in meine App einzufügen, wie den folgenden Code.

var tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: "rootPlayView")

var builder = GAIDictionaryBuilder.createScreenView()
tracker.send(builder.build() as [NSObject : AnyObject])

Dann bekam ich einen Fehler wie diesen

 enter image description here

wie kann ich das beheben?

Vielen Dank!

25

typkonverson

 enter image description here

Swift3

Bildschirmspur

 let tracker = GAI.sharedInstance().defaultTracker
 tracker.set(kGAIScreenName, value: "Home")
 tracker.send(GAIDictionaryBuilder.createScreenView().build() as [AnyHashable : Any])

Ziel c

 id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
// Set the screen name on the tracker so that it is used in all hits sent from this screen.
[tracker set:kGAIScreenName value:@"Home"];
[tracker send:[[GAIDictionaryBuilder createScreenView]  build]]; 

Automatische Bildschirmverfolgung

Swift3

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self!.screenName = "About Screen"
}

Ziel c

- (void)viewDidAppear:(BOOL)animated {
 [super viewDidAppear:animated];
  self.screenName = @"About Screen";
}

event Track

Swift3

 let tracker = GAI.sharedInstance().defaultTracker
 tracker!.send(GAIDictionaryBuilder.createEventWithCategory("ui_action", action: "button_press", label: "menuButton", play: nil).build())

Ziel c

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"     // Event category (required)
                                                  action:@"button_press"  // Event action (required)
                                                   label:@"play"           
                                                   value:nil] build]];

oder benutze

weak var tracker = GAI.sharedInstance().defaultTracker
// Set screen name on the tracker to be sent with all hits.
 tracker!.set(kGAIScreenName, value: "Home Screen")
// Send a screen view for "Home Screen".
// [tracker send:[[GAIDictionaryBuilder createAppView] build]];   

// Previous V3 SDK versions.
tracker!.send(GAIDictionaryBuilder.createScreenView().build())

// SDK Version 3.08 and up.
// This event will also be sent with &cd=Home%20Screen.
tracker!.send(GAIDictionaryBuilder.createEventWithCategory("UX", action: "touch", label: "menuButton", value: nil).build())
// Clear the screen name field when we're done.
tracker!.set(kGAIScreenName, value: nil)

weitere Informationen finden Sie unter this

beispiel

versuche dies 

var builder = GAIDictionaryBuilder.createScreenView().build() as! [NSObject : AnyObject]
tracker.send(builder)

für Bildschirmspur

let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIDescription, value: "rootPlayView")
let builder: NSObject = GAIDictionaryBuilder.createScreenView().build()
tracker.send(builder as! [NSObject : AnyObject])

für event Track

  let tracker = GAI.sharedInstance().defaultTracker
let builder: NSObject = GAIDictionaryBuilder.createEventWithCategory(
            "xxxx",
            action: "buttonclicked",
            label: "you pressed xxx button",
            value: nil).build()
tracker.send(builder as! [NSObject : AnyObject])
45
Anbu.Karthik

Diese Antwort wurde für Swift 3 aktualisiert.

let tracker = GAI.sharedInstance().defaultTracker
let eventTracker: NSObject = GAIDictionaryBuilder.createEvent( 
                withCategory: "SomeCategory",
                action: "SomeAction",
                label: "SomeLabel",
                value: nil).build()
tracker.send(eventTracker as [NSObject : AnyObject]!)

ODER...

let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIDescription, value: "ScreenViewName")
let eventTracker: NSObject = GAIDictionaryBuilder.createScreenView().build()
tracker.send(eventTracker as! [NSObject : AnyObject])
27

Für GA 3.17.0 verwenden Sie:

let tracker = GAI.sharedInstance().defaultTracker
let builder = GAIDictionaryBuilder.createEvent(withCategory: category,
                                                     action: action,
                                                      label: nil,
                                                      value: nil).build()
tracker?.send(builder as [NSObject : AnyObject]!)

Beachten Sie den ! am Ende von [NSObject: AnyObject]!.

8
funct7

Kleine Antwort auf die erstaunlichen Antworten, in Swift 3 ist dies die Methode

let builder:NSObject = GAIDictionaryBuilder.createEvent(withCategory: category, action: eventName, label: label, value: nil).build()
0
MNassar