Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,33 @@ with your other plugins or dependencies.

## Known Limitations

### Graph API Version

The Facebook SDK v18.x ships with an outdated default Graph API version that Meta has already removed:

| Platform | SDK default | Removed by Meta |
|---|---|---|
| iOS SDK v18.x | `v17.0` | September 12, 2025 |
| Android SDK v18.x | `v16.0` | May 14, 2025 |

This plugin works around the issue by overriding the Graph API version to `v24.0` at initialization. This is transparent and requires no configuration for the vast majority of apps.

If you need to target a specific Graph API version (e.g. to pin to the same version as your backend), call `setGraphApiVersion` **before** `activateApp`:

```dart
final facebookAppEvents = FacebookAppEvents();

// Override the Graph API version (optional — plugin defaults to v24.0)
await facebookAppEvents.setGraphApiVersion('v24.0');

// Then activate the app as usual
await facebookAppEvents.activateApp();
```

Refer to Meta's [Graph API changelog](https://developers.facebook.com/docs/graph-api/changelog/) for currently active versions.

This is a plugin-specific workaround for a [known upstream issue in the iOS SDK](https://github.com/facebook/facebook-ios-sdk/issues/2610) and [Android SDK](https://github.com/facebook/facebook-android-sdk/issues/1308). When Meta releases SDK v19.x with a corrected default, this override will become a no-op and the method can safely be removed from your code.

### Facebook Event Manager "Please Upgrade SDK" Warning

When setting up codeless events in Facebook Event Manager, you may encounter a warning message stating:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class FacebookAppEventsPlugin: FlutterPlugin, MethodCallHandler {
application = flutterPluginBinding.applicationContext.applicationContext as? Application
appEventsLogger = AppEventsLogger.newLogger(flutterPluginBinding.applicationContext)
anonymousId = AppEventsLogger.getAnonymousAppDeviceGUID(flutterPluginBinding.applicationContext)

// Override the Graph API version because Facebook Android SDK v18.x still defaults to v16.0,
// which was removed by Meta on May 14, 2025. This is a known upstream issue:
// https://github.com/facebook/facebook-android-sdk/issues/1308
// Note: the SDK emits a Log.w in release builds when this is called, but the version is
// still applied. This is intentional and correct behavior for a plugin.
FacebookSdk.setGraphApiVersion("v24.0")
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
Expand All @@ -61,6 +68,7 @@ class FacebookAppEventsPlugin: FlutterPlugin, MethodCallHandler {
"getAnonymousId" -> handleGetAnonymousId(call, result)
"logPurchase" -> handlePurchased(call, result)
"setAdvertiserTracking" -> handleSetAdvertiserTracking(call, result)
"setGraphApiVersion" -> handleSetGraphApiVersion(call, result)

else -> result.notImplemented()
}
Expand Down Expand Up @@ -123,6 +131,16 @@ class FacebookAppEventsPlugin: FlutterPlugin, MethodCallHandler {
result.success(anonymousId)
}

private fun handleSetGraphApiVersion(call: MethodCall, result: Result) {
val version = call.arguments as? String
if (version == null) {
result.error("INVALID_ARGUMENT", "Graph API version string is required", null)
return
}
FacebookSdk.setGraphApiVersion(version)
result.success(null)
}

private fun handleSetAdvertiserTracking(call: MethodCall, result: Result) {
val enabled = call.argument<Boolean>("enabled") ?: false
val collectId = call.argument<Boolean>("collectId") ?: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class FacebookAppEventsPlugin: NSObject, FlutterPlugin {
// "Removal of Auto Initialization of SDK" section
ApplicationDelegate.shared.initializeSDK()

// Override the Graph API version because Facebook iOS SDK v18.x still defaults to v17.0,
// which was removed by Meta on September 12, 2025. This is a known upstream issue:
// https://github.com/facebook/facebook-ios-sdk/issues/2610
Settings.shared.graphAPIVersion = "v24.0"

registrar.addMethodCallDelegate(instance, channel: channel)
registrar.addApplicationDelegate(instance)
}
Expand Down Expand Up @@ -60,6 +65,8 @@ public class FacebookAppEventsPlugin: NSObject, FlutterPlugin {
handleHandleGetAnonymousId(call, result: result)
case "setAdvertiserTracking":
handleSetAdvertiserTracking(call, result: result)
case "setGraphApiVersion":
handleSetGraphApiVersion(call, result: result)
default:
result(FlutterMethodNotImplemented)
}
Expand Down Expand Up @@ -199,6 +206,15 @@ public class FacebookAppEventsPlugin: NSObject, FlutterPlugin {
result(nil)
}

private func handleSetGraphApiVersion(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
guard let version = call.arguments as? String else {
result(FlutterError(code: "INVALID_ARGUMENT", message: "Graph API version string is required", details: nil))
return
}
Settings.shared.graphAPIVersion = version
result(nil)
}

private func handleSetAdvertiserTracking(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? [String: Any] ?? [:]
let enabled = arguments["enabled"] as? Bool ?? false
Expand Down
17 changes: 17 additions & 0 deletions lib/facebook_app_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,23 @@ class FacebookAppEvents {
);
}

/// Overrides the Graph API version used by the Facebook SDK.
///
/// The plugin sets a default Graph API version at initialization because the
/// Facebook SDK v18.x ships with an outdated default that has been removed by
/// Meta. Call this method **before** [activateApp] if you need a specific version.
///
/// The [version] string must be in the form `"vX.Y"` (e.g. `"v24.0"`).
/// Refer to Meta's [Graph API changelog](https://developers.facebook.com/docs/graph-api/changelog/)
/// for currently supported versions.
///
/// See documentation:
/// - [iOS Settings](https://developers.facebook.com/docs/reference/iossdk/current/FBSDKCoreKit/classes/settings.html)
/// - [Android FacebookSdk](https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/FacebookSdk.html)
Future<void> setGraphApiVersion(String version) {
return _channel.invokeMethod<void>('setGraphApiVersion', version);
}
Comment on lines +517 to +519
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new setGraphApiVersion method lacks test coverage. Based on the existing test patterns in test/facebook_app_events_test.dart, there should be at least one test verifying that the method correctly invokes the platform channel with the expected method name and version argument. For example:

test('setGraphApiVersion forwards version string', () async {
  await facebookAppEvents.setGraphApiVersion('v24.0');
  expect(
    methodCall,
    isMethodCall('setGraphApiVersion', arguments: 'v24.0'),
  );
});

Copilot uses AI. Check for mistakes.

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
//
Expand Down