This document introduces the integration method of TopOn SDK in Flutter platform, from application account, appid, AD id and integration SDK to describe, to ensure that developers can successfully integrate SDK for cash. TopOn SDK's Flutter platform currently supports Splash ads, Reward videos, interstitial ads, banner ads, and native ads.
You can use the TopOn account and related ID to prepare the operation instructions for account registration and login.
Flutter version requirements: flutter: ">=2.12.0"
Reference Demo Flutter Demo Github address.
Note: Choose one of the following two methods Just import anythink_sdk
Note: Flutter SDK needs to be used with the Android or iOS SDK. For details, please refer to chapters 4.1 and 5.1 below
Run the following command in the terminal command line:
flutter pub add anythink_sdk
After running the command, the In pubspec.yaml, automatically add the following similar to code (and trigger flutter pub get)
dependencies:
anythink_sdk: ^1.0.4
Introduce the header file into the class file
import 'package:anythink_sdk/at_index.dart';
Note: Flutter SDK needs to be used with Android or iOS SDK. For details, please refer to chapters 4.1 and 5.1 below
Configuration requirements:
Xcode version 14 and above.
iOS 9.0 and higher
Please go to TopOn Download page, check the platform that needs to be integrated, and click download; after the download is complete, decompress the downloaded compressed package (as shown in the figure): Operation After completion, please see step 4.4 for the next step.
Put the downloaded SDK into a new folder, named as desired, ThirdPartySDK in the figure as an example, copy the decompressed file to the ThirdPartySDK folder, the folder in the picture:
Then open the anythink_sdk.podspec file (see figure) comment, modify the path of the SDK library in the red box, and open the comment after the modification.
Please go to TopOn Download page, check the platform that needs to be integrated, and click to generate Cocoapod reference code: the operation is completed Please see step 4.4 to complete the next step.
Copy the code generated in the previous step, and then modify it to the following dependency code:
s.dependency 'TPNSDKiOS','6.3.67'
Add in anythink_sdk.podspec file :
When using anythink_sdk added by pub.dev, you need to find the path of anythink_sdk.podspec to import the iOS native advertising SDK in 4.2 or 4.3. You can obtain it through the following steps:
1. Complete pub. After importing the dev command, open the Flutter project, select any class file to import the header file, and place the mouse within the scope of the header file
import 'package:anythink_sdk/at_index.dart';
2. Copy the red box address in the dialog box that pops up in the development tool, and use Finder to open it to find the location of anythink_sdk.podspec.
For the above manual import and Cocoapods import, after writing anythink_sdk.podspec, use the terminal to open the directory where iOS is located and wait for the installation to complete.
// input code
pod install --repo -update
Finally, you need to set the value of Xcode's Other Linker and add -ObjC, as shown in the figure.
Register the SDK plug-in in the GeneratedPluginRegistrant class in the generated Android project
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new com.anythink.flutter.AnythinkSdkPlugin());
}
}
1. Please go to TopOn Download page, check the platform that needs to be integrated, and click Download; after the download is complete, unzip the downloaded Android SDK compressed package.
2. (If there is a libs directory in the compressed package and there are files in the libs directory) Copy the libs directory in the Android SDK compressed package to plugins /anythink_sdk/android/ directory, and add the following configuration in the project's build.gradle:
Note: <plugins/anythink_sdk> Replace with the actual path where the anythink_sdk folder is placed in the project
dependencies {
api fileTree(dir: '<plugins/anythink_sdk>/android/libs', include: ['*.aar', '*.jar'])
}
3. (If there is a build.gradle file in the compressed package) Copy the contents of build.gradle in the compressed package to the project build.gradle
4. (If there is a res directory in the compressed package and there are files in the res directory) Copy the contents of the res directory in the Android SDK compressed package to the res directory of the project
Since the advertising alliance platform resources may have HTTP links, this permission needs to be enabled, otherwise the ad display may not be filled with material. Add support in ios/Runner/Info.plis.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
SDK It does not contain code to obtain positioning permissions, nor does it actively request positioning permissions. It is optional. Projectios/Runner/Info.plis File settings, click the "+" behind the information Property List on the right to expand and add Privacy - Location When In Use Usage Description.
Starting from iOS 14.5+, Apps can only access a user's IDFA data and serve targeted ads to the user with the user's explicit permission. Please see the detailed iOS 14.5+ support notes for more information.
1.0 Update Info.plist , add the NSUserTrackingUsageDescription field and custom copy description. Suggestions for pop-up small text copywriting: Obtain tag permissions to provide you with better and safer personalized services and content. We will not use it for other purposes without your consent; after turning it on, you will also You can turn it off at any time by going to the system "Settings-Privacy". Obtain IDFA tag permission to provide you with better, safer and personalized services and content; after turning it on, you can also go to the system "Settings - Privacy" to turn it off at any time.
Such as:
// Chinese
<key>NSUserTrackingUsageDescription</key>
<string>获取标记权限向您提供更优质、安全的个性化服务及内容,未经同意我们不会用于其他目的;开启后,您也可以前往系统“设置-隐私 ”中随时关闭</string>
// English
<key>NSUserTrackingUsageDescription</key>
<string>Obtain the rights to mark to provide you with better and safer personalized services and content, without consent we will not use for other purposes; After opening, you can also go to the system "Settings - Privacy" at any time to close</string>
1.1 Apply for permission from the user Initialize the SDK, which will automatically apply for permissions from the user based on the iOS version
SKAdNetwork is a way to receive attribution data for marketing promotions on iOS. Add the following SKAdNetwork IDs to info.plist to ensure correct operation of SKAdNetwork. Add the corresponding SKAdNetworkID according to the docking platform. If there is no docking platform SKNetworkID, there is no need to add it. Please go to TopOn download page Generate SkAdnetwork IDs code
If you have imported the Admob advertising platform SDK, then You also need to add GADApplicationIdentifier to your ios/Runner/Info.plist to configure your Admob AppID.
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-***********~**********</string>
<key>GADIsAdManagerApp</key>
<true/>
1. Add the contents of AndroidManifest.xml in the Android SDK compressed package to AndroidManifest.xml in the project.
2、If Admob is aggregated, the following configuration must be added to AndroidManifest.xml (the value needs to configure the ID of the application created in the Admob background):
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
For details, please refer to the Admob configuration documentation:AndroidManifest.xml
Please refer to: Adaptation for Android 9 and above
1. Flutter SDK obfuscation configuration
-keep public class com.anythink.flutter.**
-keepclassmembers class com.anythink.flutter.** {
public *;
}
2. Android SDK advertising platform obfuscation configuration
Please refer to: proguard-android.txt in the Android SDK compressed package content