This documentation is a brief introduction to Appsfire SDK for Unity. We recommend you to take a look on the general documentation that you can find in your dashboard. Most of methods were implemented in Unity. If you have a problem during the integration, don't hesitate to contact us at [email protected].
Although the plugin can be used by most of Unity versions, the demo project requires Unity 5.
We recommend you to read the integration reference documentation that you find at this url http://docs.appsfire.com/.
First you need to add Appsfire SDK files into your Unity project. For this you have two possibilities.
Appsfire provides you a package named "AppsfireSDK.unitypackage" that you can import from Unity. Just do a right-click on the "project" part, select "Import Package" / "Custom Package", and choose the AppsfireSDK.unitypackage file.
Once you selected the package, you'll have to verify the imported files. You don't have to unbox something, you can directly click on "Import".
Otherwise, you can directly copy paste the files from /AppsfireSDKDemo/Assets/Plugins.
There are 5 important files that you need to be aware of:
- AppsfireSDKPrefab.prefab : prefab to include in your project. It'll be used for the communication between our library and Unity.
- AppsfireSDK.cs : the "base" library (e.g. initialize the library).
- AppsfireEngageSDK.cs : the "engage" library (e.g. displaying notifications view, handling push system, ...).
- AppsfireAdSDK.cs : the "monetization" library (e.g. displaying ads to do money).
- AppsfireSDKEvents.cs : subscribing and receiving any event related the "engage" and "monetization" library.
For the following example, we recommend you to take a look at AppsfireSDKDemo.cs file which is in the demo project included in the zip (with the unitypackage).
Some actions are required to correctly initialize AppsfireSDK and get events. So please make sure that:
- The prefab
AppsfireSDKPrefab.prefab
is included in your project. - The script
AppsfireSDKEvents.cs
is added to your prefab
In your Start() method, you need to add a required initialization method where you put your API KEY. If you don't have it yet, please check the general documentation which explains how to get it thanks to your dashboard.
As second parameter, you should precise what features you want to enable. For exaemple, if you plan to only use monetization SDK (to display ads), then you should put AFSDKFeature.AFSDKFeatureMonetization
.
// af sdk - connect with your api key
AppsfireSDK.ConnectWithAPIKey("YOUR API KEY", AFSDKFeature.AFSDKFeatureMonetization);
To display the notifications wall, you just have to call the following method.
AppsfireEngageSDK.PresentPanelForContentAndStyle(AFSDKPanelContent.AFSDKPanelContentDefault, AFSDKPanelStyle.AFSDKPanelStyleFullscreen);
You can customize the experience by specifying custom colors. But it's best to add the following lines in the Start() method!!!
AF_RGBA backgroundColor, textColor;
// af sdk - customize background and text colors
// these values are default colors, you can customize with the colors of your app
backgroundColor = new AF_RGBA(66.0/255.0, 67.0/255.0, 69.0/255.0, 1.0);
textColor = new AF_RGBA(1.0, 1.0, 1.0, 1.0);
AppsfireEngageSDK.SetBackgroundAndTextColor(backgroundColor, textColor);
It's easy to display ads during breakout sessions.
When you are ready to display an ad, you just have to check if any is available, and then request it!
if (AppsfireAdSDK.IsThereAModalAdAvailable())
AppsfireAdSDK.RequestModalAd(AFAdSDKModalType.AFAdSDKModalTypeSushi);
You can be alerted that an ad is available thanks to an event. So you can directly display the ad! or wait a breakout session to display it.
void OnEnable()
{
AppsfireSDKEvents.afsdkadModalAdsRefreshedAndAvailable += this.afsdkadModalAdsRefreshedAndAvailable;
}
void OnDisable()
{
AppsfireSDKEvents.afsdkadModalAdsRefreshedAndAvailable -= this.afsdkadModalAdsRefreshedAndAvailable;
}
public void afsdkadModalAdsRefreshedAndAvailable()
{
Debug.Log("Appsfire Ad SDK - Modal Ad Refreshed And Available For Request");
if (AppsfireAdSDK.IsThereAModalAdAvailable(AFAdSDKModalType.AFAdSDKModalTypeUraMaki) == AFAdSDKAdAvailability.AFAdSDKAdAvailabilityYes) {
AppsfireAdSDK.RequestModalAd(AFAdSDKModalType.AFAdSDKModalTypeSushi);
}
}
You can easily register and get events from any place of your code.
Here is an example if you want to know when the badge counter is updated.
void OnEnable()
{
AppsfireSDKEvents.afsdkNotificationsNumberChanged += this.afsdkNotificationsNumberChanged;
}
void OnDisable()
{
AppsfireSDKEvents.afsdkNotificationsNumberChanged -= this.afsdkNotificationsNumberChanged;
}
// notifications count was updated
public void afsdkNotificationsNumberChanged()
{
Debug.Log("Appsfire SDK - Number of Notifications was updated");
int numberOfNotifications = AppsfireSDK.NumberOfPendingNotifications();
}
If you don't get any event, it's likely that the prefab isn't used in your project.
We're using the project XUPorter
to automatically add some frameworks to your Xcode project. If you're building the demo project, it should directly work! (you can find the plugin in /Assets/Editor/XUPorter).
Note: It seems that since Unity 5, XUPorter has difficulties adding AdSupport.framework
after the build of the iOS project. Thus you may have to manually add it to your Xcode after the build.
When you're implementing the sdk into your project, you can either use XUPorter, or manually add the following frameworks after the build that creates the Xcode projet:
- Accelerate
- AdSupport
- CoreText
- Security
- StoreKit