Facebook Analytics Push on iOS works sometimes

I struggled with this for a while, but I finally succumbed to the question of whether anyone else had a problem.

Essentially, I'm trying to use the Facebook Analytics push service and it seems like I sometimes get push notifications. I intercepted API calls using charles proxy to ensure that push tokens are sent correctly by the Facebook SDK and events are logged as expected. From this point of view, everything is in order.

Then I use the "Check Campaign Push Settings" on the settings page to try and send push and in-app push tests, and they also work fine (maps display correctly on devices, etc.) on the three test devices I use.

The problem occurs when you try to create a campaign to send clicks to a specific device segment. The first device I tried to work with no problems at all, but then subsequent devices (without any changes to the code base) would not receive any clicks from any campaigns I configured. My target audience is “Device OS is iOS,” so I expect all iOS devices to get a boost from the campaign. It seemed a little strange, so I uninstalled the application from all devices and rebuilt them again (so that the test push worked on all devices) and set up the campaign again, but this time even the first device did not work anymore. In the event debugger, I get the error message "Push Notification Error" and error_message "InvalidDeviceOS", which makes no sense.

I come back and fourth with this for several hours without success. I see that tokens are sent to Facebook, and I see that events are logged in the event debugger, I can use the push test service in the settings, and all devices get clicked without problems, but as soon as I try to use I get nothing.

For completion purposes, here are snippets of the code I'm using:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // ...
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
    // ...
}

func application(application: UIApplication, didRegisterUserNotificationSettings settings: UIUserNotificationSettings) {
    UIApplication.sharedApplication().registerForRemoteNotifications()
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    FBSDKAppEvents.setPushNotificationsDeviceToken(deviceToken)
}

Finally, it is an event debugger after opening a new installation on 3 different devices (see the first launch events, 2 application launches have IDs and 1 does not work until it is logged in).

enter image description here

Any help with this would be great, thanks.

. Facebook-, push .. , , . . , , ... !

, . , Facebook, , , APP APNS, , .

:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil))

    return true
}

func applicationDidBecomeActive(_ application: UIApplication) {

    FBSDKAppEvents.activateApp()
}

// MARK: Notification Methods

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

    application.registerForRemoteNotifications()
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    FBSDKAppEvents.setPushNotificationsDeviceToken(deviceToken)
    FBSDKAppEvents.setUserID(NSUUID().uuidString)

    var token: String = ""
    for i in 0 ..< deviceToken.count {
        token += String(format: "%02.2hhx", deviceToken[i] as CVarArg)
    }
    print("Token: \(token)")
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    if FBNotificationsManager.shared().canPresentPushCard(fromRemoteNotificationPayload: userInfo) {

        FBNotificationsManager.shared().presentPushCard(forRemoteNotificationPayload: userInfo, from: nil, completion: nil)

    } else {

        print("Unknown Payload")
    }

    completionHandler(.newData)
}

UPDATE 2: Facebook, , , : https://developers.facebook.com/bugs/118059088679219/

+4

Source: https://habr.com/ru/post/1663137/


All Articles