I'm trying to implement Integration the SponsorPay Offerwall to my iOS application, but I can't understand how determine when user finished watching video and how many virtual coins he gained. In documentation I did not found solution :(
1 Answers
When the user finishes watching the video the delegate you registered when initializing the SPBrandEngageClient
instance will have its brandEngageClient:didChangeStatus:
method invoked.
What you will be looking for to find out when the user finished watching the video is whether the status received by this method is CLOSE_FINISHED
.
If you get CLOSE_ABORTED
instead, that means your user has closed the engagement before watching the video completely.
All the statuses are defined and described in the SPBrandEngageClientStatus
enum that you can find in the SPBrandEngageClient.h
file. It's also described in the Integrating_mBE_SDK.md documentation file, on the table at the end of the section "Requesting and showing engagements".
Your delegate must conform to the SPBrandEngageClientDelegate
protocol, defined in the same header file.
Here's an example of initialization of the SPBrandEngageClient
instance:
_brandEngageClient =
[[SPBrandEngageClient alloc] initWithAppId:@"YOUR_APP_ID"
userId:@"CURRENT_USER_ID"
delegate:self]; // <-- this is your delegate
And here's an example of your brandEngageClient:didChangeStatus:
delegate method:
- (void)brandEngageClient:(SPBrandEngageClient *)brandEngageClient
didChangeStatus:(SPBrandEngageClientStatus)newStatus
{
switch (newStatus) {
case STARTED:
// Your user just started watching the engagement
break;
case CLOSE_FINISHED:
// This is it! Your user finished watching the video
break;
case CLOSE_ABORTED:
// Engagement was cancelled
break;
case ERROR:
// Something prevented the engagement from working correctly
break;
}
}
Determining how many virtual coins the user gained
If your brandEngageClient:didChangeStatus:
delegate method receives the CLOSE_FINISHED
status notification you can safely assume that your user will receive a payout. Determining the size of this payout cannot be done instantly, for it takes some time for the server to process it. The current SDK implementation requires that you poll the server periodically until you get an earned amount greater than 0. For that purpose you can use the provided SPVirtualCurrencyServerConnector
class. Here's a guide to its usage with some example code (in this guide the class is described as SPVirtualCurrencyServerConnection instead, but the process is the same).
When the coins do arrive, your user will see a little notification briefly appear on the screen with the amount they earned, unless you disable it setting your SPBrandEngageClient
instance's shouldShowPayoffNotificationOnVirtualCoinsReceived
property to NO
.

- 11
- 1