8

I am trying to add facebook app events, and I installed FacebookSDK. Then I have next code:

import FacebookCore

static func logViewContentEvent(contentType : String, contentData : String, contentId : String, currency : String, price : Double) {
        let params : AppEvent.ParametersDictionary = [
            .contentType : contentType,
            .content : contentData,
            .contentId : contentId,
            .currency : currency
        ]
        let event = AppEvent(name: .viewedContent, parameters: params, valueToSum: price)
        AppEventsLogger.log(event)
    }

But I get error from the title. What I am doing wrong, and why this type is missing?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Whirlwind
  • 14,286
  • 11
  • 68
  • 157

3 Answers3

8

It's a knowed facebook annoying issue.

Before FBSDK 5.0.1 your code works well. After, you can change your code with for example:

static func logViewContentEvent(contentType : String, contentData : String, contentId : String, currency : String, price : Double) {
        let params =  [
            "contentType": contentType,
            "content" : contentData,
            "contentID" : contentId,
            "currency" : currency
        ]
        AppEvents.logEvent(AppEvents.Name(rawValue: "viewedContent"), valueToSum: price, parameters: params)
    }
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • 1
    It works like this, but its kinda hacky way to achive what I wanted. Well, its only solution for now I guess. Thanks for the answer man. – Whirlwind Dec 06 '19 at 14:19
4

In top of file get rid of FacebookCore use only

         import FBSDKCoreKit
         // implemented  FBSDKCoreKit (5.8.0)
         let event =  "custom event"
         AppEvents.logEvent(AppEvents.Name.init(rawValue: event))

or with parameters

    let a:[String: String] = ["key": "value"]
    AppEvents.logEvent(AppEvents.Name.init(rawValue: event), parameters: a )
ares777
  • 3,590
  • 1
  • 22
  • 23
0

I have mine working with these set up:

  • Installed via cocoapod with use_frameworks! configuration

pod 'FBSDKCoreKit', '~> 5.11.1'

  • Since my project supports both ObjC and Swift I imported <FBSDKCoreKit/FBSDKCoreKit.h> on the bridging file
static func logContent(id: String, type: String, valueToSum: Double) {
        AppEvents.logEvent(.viewedContent,
                           valueToSum: valueToSum,
                           parameters: [contentType: type,
                                        contentID: id,
                                        currency: "USD"])
    }
Teffi
  • 2,498
  • 4
  • 21
  • 40
  • This ways work for me to. Checkout actually my code in original question. There is no type AppEvent etc... AppEvents exists. – Whirlwind Dec 06 '19 at 14:24
  • oh. sorry. I missed out that you're referring to logging custom events. Let me try and see if I can find something that will help – Teffi Dec 06 '19 at 14:33
  • I am trying to log standard events with the code generated with Facebook code generator. The code is broken, it doesnt work. What you are posting works for me to. – Whirlwind Dec 06 '19 at 14:41
  • @Whirlwind Sorry for the confusion. I would stick with what Alessandro Ornano suggested. I think the docs are probably outdated and `AppEvent` is something they've entirely removed. – Teffi Dec 06 '19 at 14:47