नेटवर्क विशिष्ट API का उपयोग करना

मीडिएशन नेटवर्क अपने Android और iOS SDK टूल में एपीआई उपलब्ध करा सकते हैं. इनकी मदद से, विज्ञापन को अपनी पसंद के मुताबिक बनाने की सुविधा मिलती है. प्लैटफ़ॉर्म चैनल का इस्तेमाल करके, इन एपीआई को डार्ट कोड से कॉल किया जा सकता है.

नीचे दिए गए सैंपल में, AppLovin के Android और iOS SDK टूल में, Dart से निजता के एपीआई को कॉल करने का तरीका बताया गया है.

डार्ट में तरीके का चैनल बनाएं

अपने डार्ट कोड में, तरीके के मुताबिक चैनल बनाएं:

/// Wraps a method channel that makes calls to AppLovin privacy APIs.
class MyMethodChannel {
  final MethodChannel _methodChannel =
      MethodChannel('com.example.mediationexample/mediation-channel');

  /// Sets whether the user is age restricted in AppLovin.
  Future<void> setAppLovinIsAgeRestrictedUser(bool isAgeRestricted) async {
    return _methodChannel.invokeMethod(
      'setIsAgeRestrictedUser',
      {
        'isAgeRestricted': isAgeRestricted,
      },
    );
  }

  /// Sets whether we have user consent for the user in AppLovin.
  Future<void> setHasUserConsent(bool hasUserConsent) async {
    return _methodChannel.invokeMethod(
      'setHasUserConsent',
      {
        'hasUserConsent': hasUserConsent,
      },
    );
  }
}

अपने Android कोड में बदलाव करना

Android में AppLovin SDK टूल को एपीआई कॉल करने के लिए, तरीके का चैनल सेट अप करें:

public class MainActivity extends FlutterActivity {
  private static final String CHANNEL_NAME =
    "com.example.mediationexample/mediation-channel";

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    super.configureFlutterEngine(flutterEngine);

    // Set up a method channel for calling APIs in the AppLovin SDK.
    new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
        .setMethodCallHandler(
          (call, result) -> {
            switch (call.method) {
              case "setIsAgeRestrictedUser":
                AppLovinPrivacySettings.setIsAgeRestrictedUser(call.argument("isAgeRestricted"), context);
                result.success(null);
                break;
              case "setHasUserConsent":
                AppLovinPrivacySettings.setHasUserConsent(call.argument("hasUserConsent"), context);
                result.success(null);
                break;
              default:
                result.notImplemented();
                break;
            }
          }
        );
  }
}

अपना iOS कोड बदलना

iOS में AppLovin SDK टूल को एपीआई कॉल करने के लिए, तरीके का चैनल सेट अप करें:

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];

  // Set up a method channel for calling methods in 3P SDKs.
  FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;

  FlutterMethodChannel* methodChannel = [FlutterMethodChannel
                                          methodChannelWithName:@"com.example.mediationexample/mediation-channel"
                                          binaryMessenger:controller.binaryMessenger];
  [methodChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
    if ([call.method isEqualToString:@"setIsAgeRestrictedUser"]) {
      [ALPrivacySettings setIsAgeRestrictedUser:call.arguments[@"isAgeRestricted"]];
      result(nil);
    } else if ([call.method isEqualToString:@"setHasUserConsent"]) {
      [ALPrivacySettings setHasUserConsent:call.arguments[@"hasUserConsent"]];
      result(nil);
    } else {
      result(FlutterMethodNotImplemented);
    }
  }];
}
@end

Dart में अपने MethodChannel का इस्तेमाल करना

अब MyMethodChannel का इस्तेमाल करके, Dart से AppLovin Privacy API को कॉल किया जा सकता है:

/// An example widget for the home page of your app.
class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  
  // Keep a reference to your MyMethodChannel.
  static MyMethodChannel platform = MyMethodChannel();
  
  @override
  void initState() {
    super.initState();

    _updateAppLovinSettingsAndLoadAd();
  }
  
  Future<void> _updateAppLovinSettingsAndLoadAd() async {
    // Update the AppLovin settings before loading an ad.
    await platform.setAppLovinIsAgeRestrictedUser(true);
    await platform.setHasUserConsent(false);
    _loadAd();
  }
  
  void _loadAd() {
    // TODO: Load an ad.
  };

  @override
  Widget build(BuildContext context) {
    // TODO: Build your widget.
  }
}

Android और iOS दस्तावेज़ में, अन्य नेटवर्क पर काम करने वाले एपीआई के बारे में ज़्यादा जानकारी मिल सकती है.