简体   繁体   中英

Facebook ios sdk in iOS 14.5 can not send app events

I develop a sdk for my game. In ios under 14, everything work well, I can see event in facebook analystic and business event manager. But above ios 14, I can't see anything. What i try:

-Add Ska.network info to Info.plist:

    <key>SKAdNetworkItems</key>
    <array>
        <dict>
            <key>SKAdNetworkIdentifier</key>
            <string>v9wttpbfk9.skadnetwork</string>
        </dict>
        <dict>
            <key>SKAdNetworkIdentifier</key>
            <string>n38lu8286q.skadnetwork</string>
        </dict>
    </array>

-Integrate facebook sdk:

Add facebook's app id, facebook's client token

+ (void) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
   
    
    [AppsFlyerLib shared].delegate = SDK.self;
    [AppsFlyerLib shared].isDebug = false;
    
    [FIRApp configure];
    //  [FIRMessaging messaging].delegate = SDK.self;
    
    
    if (@available(iOS 10.0, *)) {
        // iOS 10 or later
        // For iOS 10 display notification (sent via APNS)
        [UNUserNotificationCenter currentNotificationCenter].delegate = ESGameSDK.self;
        UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
        UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
        [[UNUserNotificationCenter currentNotificationCenter]
         requestAuthorizationWithOptions:authOptions
         completionHandler:^(BOOL granted, NSError * _Nullable error) {
            // ...
        }];
    } else {
        // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
        UIUserNotificationType allNotificationTypes =
        (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        [application registerUserNotificationSettings:settings];
    }
    
    [application registerForRemoteNotifications];
   /**
    [FBSDKSettings enableLoggingBehavior:FBSDKLoggingBehaviorAppEvents];
    [FBSDKSettings setAdvertiserIDCollectionEnabled:TRUE];
   [FBSDKSettings setAdvertiserTrackingEnabled:TRUE];
    [FBSDKSettings setAutoLogAppEventsEnabled:YES];
    */
 
    if (@available(iOS 14, *)) {
        //if(ATTrackingManager.trackingAuthorizationStatus == ATTrackingManagerAuthorizationStatusAuthorized)
            //[FBSDKSettings setAdvertiserTrackingEnabled:TRUE];
        //else{
            //[FBSDKSettings setAdvertiserTrackingEnabled:NO];
        //}
    } else {
        //[FBSDKSettings setAdvertiserTrackingEnabled:TRUE];
    }
  /** 
 [SDK checkTrackingAuthorization:^(bool status) {
        [TrackingHelper firstAppLaunch];
        //[FBSDKAppEvents logEvent:@"tracking_authorized"];
    }];
   */
    if (launchOptions[UIApplicationLaunchOptionsURLKey] == nil) {
        [FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) {
            if (error) {
                NSLog(@"Received error while fetching deferred app link %@", error);
            }
            if (url) {
                [[UIApplication sharedApplication] openURL:url];
            }
        }];
    }
  
}
+(void)checkTrackingAuthorization:(void(^)(bool status))callback{
    if (@available(iOS 14.5, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            NSLog(@" ATTrackingManagerAuthorizationStatus %lu",(unsigned long)status);
            NSLog(@" ATTrackingManagerAuthorizationStatus %lu",(unsigned long)ATTrackingManagerAuthorizationStatusAuthorized);
            bool rs = status == ATTrackingManagerAuthorizationStatusAuthorized;
            if(rs){
                [FBSDKSettings setAdvertiserTrackingEnabled:YES];
            }else{
                //[FBSKSettings setAdvertiserTrackingEnabled:NO];
            }
            callback(true);
        }];
        
    } else {
        callback(true);
    }
}
+ (BOOL) application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                  openURL:url
                                                        sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                               annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
     ];
    [[GIDSignIn sharedInstance] handleURL:url ];
    [[AppsFlyerLib shared] handleOpenUrl:url options:options];
    return true;
}

+ (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                  openURL:url
                                                        sourceApplication:sourceApplication
                                                               annotation:annotation
     ];
    [[GIDSignIn sharedInstance] handleURL:url];
    [[AppsFlyerLib shared] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
    return true;
}

+ (void) applicationDidBecomeActive:(UIApplication *)application {
    /**
    [FBSDKSettings setAdvertiserIDCollectionEnabled:TRUE];
    [FBSDKSettings setAutoLogAppEventsEnabled:TRUE];
    //[FBSDKSettings setAdvertiserTrackingEnabled:TRUE];
     */
    [[AppsFlyerLib shared] start];
    [SDK checkTrackingAuthorization:^(bool status) {
        [TrackingHelper firstAppLaunch];
        //[FBSDKAppEvents logEvent:@"tracking_authorized"];
    }];  
}

-And send app event like this:

[FBSDKAppEvents logEvent:@"register" valueToSum:1 parameters:@{
        @"uId":user.name,
        @"provider":user.provider
        
    }];

Note: I use facebook sdk 11.

Do I miss something? Sorry for my bad English.

This is an undocumented issue that is caused by you having tracking disabled on your iOS14+ device.

Go to iOS settings > privacy > tracking > enable tracking; launch the facebook app and wait for it to prompt permission to track and accept. If it doesn't go to iOS settings > facebook > tracking and turn on then relaunch fb app for a moment. Now relaunch your app and events will fire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM