'Code module
#Region Project Attributes
#ApplicationLabel: RewardedAds
#Version: 1.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait
#iPadOrientations: Portrait
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 12
#PlistExtra: <key>GADIsAdManagerApp</key><true/>
#AdditionalLib: libsqlite3.dylib
#AdditionalLib: libz.dylib
#AdditionalLib: WebKit.framework
#AdditionalLib: AppTrackingTransparency.framework
#PlistExtra: <key>NSUserTrackingUsageDescription</key><string>This identifier will be used To deliver personalized ads To you.</string>
#PlistExtra:<key>SKAdNetworkItems</key>
#PlistExtra: <array>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>cstr6suwn9.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>4fzdc2evr5.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>4pfyvq9l8r.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>2fnua5tdw4.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>ydx93a7ass.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>5a6flpkh64.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>p78axxw29g.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>v72qych5uu.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>ludvb6z3bs.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>cp8zw746q7.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>c6k4g5qg8m.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>s39g8k73mm.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>3qy4746246.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>3sh42y64q3.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>f38h382jlk.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>hs6bdukanm.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>prcb7njmu6.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>v4nxqhlyqp.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>wzmmz9fp6w.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>yclnxrl5pm.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>t38b2kh725.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>7ug5zh24hu.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>9rd848q2bz.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>vutu7akeur.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>y5ghdn5j9k.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>n6fk4nfna4.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>v9wttpbfk9.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>n38lu8286q.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>47vhws6wlr.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>kbd757ywx3.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>9t245vhmpl.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>eh6m2bh4zr.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>a2p9lx4jpn.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>22mmun2rn5.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>4468km3ulz.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>2u9pt9hc89.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>8s468mfl3y.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>av6w8kgt66.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>klf5c3l5u5.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>ppxm28t8ap.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>424m5254lk.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>ecpz2srf59.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>uw77j35x4d.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>pwa73g5rt2.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>mlmmfzh3r3.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>578prtvx9j.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>4dzt52r2t5.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>gta9lk7p23.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>e5fvkxwrpn.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>8c4e2ghe7u.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>zq492l623r.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>3rd42ekr43.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: <dict>
#PlistExtra: <key>SKAdNetworkIdentifier</key>
#PlistExtra: <string>3qcr597p9d.skadnetwork</string>
#PlistExtra: </dict>
#PlistExtra: </array>
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private oRVA As NativeObject
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.RootPanel.LoadLayout("Page1")
NavControl.ShowPage(Page1)
SetTestAdDeviceID("Your device test id that appear in the log")
End Sub
Sub Button1_Click
LoadNewRewardedVideoAd
End Sub
Private Sub RVA_AdOpened
Log("RVA_AdOpened")
End Sub
Private Sub RVA_AdClosed
Log("RVA_AdClosed")
ShowHideStatusBar(False)
End Sub
Private Sub RVA_FailedToOpen
Log("RVA_FailedToOpen")
End Sub
Sub RVA_FailedToLoad (ErrorCode As Int, ErrorDescription As String)
Log("RVA_FailedToLoad")
Log("ErrorCode = " & ErrorCode)
Log("ErrorDescription =" & ErrorDescription)
End Sub
Sub RVA_Loaded (RewardedAd As RewardedVideoAd)
Log("RVA_Loaded")
Dim oBlock As NativeObject = Me
Dim UserID As String = "[email protected]"
Dim CustomData As String = "Some Data"
oBlock = oBlock.RunMethod("getUserDidEarnRewardHandlerBlock", Null)
oRVA = RewardedAd
Dim oReward As NativeObject = oRVA.GetField("adReward")
Log("Type = " & oReward.GetField("type").AsString)
Log("amount = " & oReward.GetField("amount").AsNumber)
SetServerSideVerificationOptions(oRVA, UserID.Trim, CustomData.Trim)
ShowHideStatusBar(True)
oRVA.SetField("fullScreenContentDelegate", Page1)
oRVA.RunMethodWithBlocks("presentFromRootViewController:userDidEarnRewardHandler:", Array(Page1, oBlock))
End Sub
Private Sub RVA_Rewarded
Log("RVA_Rewarded")
End Sub
Private Sub SetTestAdDeviceID (TestDeviceID As String)
Dim DeviceIdentifiers As NativeObject = Me
Dim oMobileAdsSharedInstance As NativeObject
DeviceIdentifiers = DeviceIdentifiers.RunMethod("createNativeArray:", Array(TestDeviceID))
oMobileAdsSharedInstance.Initialize("GADMobileAds")
oMobileAdsSharedInstance.RunMethod("sharedInstance", Null).RunMethod("requestConfiguration", Null).SetField("testDeviceIdentifiers", DeviceIdentifiers)
End Sub
Private Sub SetServerSideVerificationOptions (RewardedAd As NativeObject, lvUserIdentifier As String, lvCustomData As String)
Dim oOptions As NativeObject
oOptions = oOptions.Initialize("GADServerSideVerificationOptions").RunMethod("alloc",Null)
If lvUserIdentifier.Trim <> "" Then oOptions.SetField("userIdentifier", lvUserIdentifier)
If lvCustomData.Trim <> "" Then oOptions.SetField("customRewardString", lvCustomData)
RewardedAd.SetField("serverSideVerificationOptions", oOptions)
End Sub
Private Sub LoadNewRewardedVideoAd As ResumableSub
Try
Dim oIDFA As NativeObject = Me
Dim ARB As AdRequestBuilder
Dim oRewaredAd As NativeObject
Dim oBlock As NativeObject = Me
oIDFA.RunMethod("requestIDFA", Null)
Wait For GAD_TrackingAuthorization (Status As Int)
If ARB.IsInitialized = False Then ARB.Initialize
If Status <> 3 Then ARB.NonPersonalizedAds
oBlock = oBlock.RunMethod("getRewardedAdLoadCompletionHandlerBlock", Null)
oRewaredAd = oRewaredAd.Initialize("GADRewardedAd").RunMethodWithBlocks("loadWithAdUnitID:request:completionHandler:", Array("Your real rewarded ad unit id", ARB, oBlock))
Return "OK"
Catch
Log(LastException)
Return "Error"
End Try
End Sub
Private Sub ShowHideStatusBar(ShowHide As Boolean)
Dim No As NativeObject = App
No.RunMethod("setStatusBarHidden:animated:", Array(ShowHide, False))
End Sub
#if OBJC
#import <UserNotifications/UserNotifications.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
- (void)requestIDFA {
if (@available(iOS 14, *)) {
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
[self.bi raiseUIEvent:nil event:@"gad_trackingauthorization:" params:@[@(status)]];
}];
} else {
[self.bi raiseUIEvent:nil event:@"gad_trackingauthorization:" params:@[@(3)]];
}
}
GADRewardedAdLoadCompletionHandler rewardedAdLoadCompletionHandlerBlock = ^(GADRewardedAd *ad, NSError *error) {
__block B4I* bi = [b4i_main new].bi;
__block B4IRewardedVideoAd *rewardedAd = [[B4IRewardedVideoAd alloc] init];
if (error) {
[bi raiseUIEvent:nil event:@"rva_failedtoload::" params:@[@([error code]),[error localizedDescription]]];
return;
}
rewardedAd.object = ad;
[bi raiseUIEvent:nil event:@"rva_loaded:" params:@[rewardedAd]];
};
- (NSObject *)getRewardedAdLoadCompletionHandlerBlock {
return rewardedAdLoadCompletionHandlerBlock;
}
GADUserDidEarnRewardHandler userDidEarnRewardHandlerBlock = ^{
__block B4I* bi = [b4i_main new].bi;
[bi raiseUIEvent:nil event:@"rva_rewarded" params:nil];
};
- (NSObject *)getUserDidEarnRewardHandlerBlock {
return userDidEarnRewardHandlerBlock;
}
- (NSArray *)createNativeArray:(NSString *) nArrayItem {
NSArray *array = @[nArrayItem];
return array;
}
#End If
#if OBJC
@end
@interface GADRewardedAd (event)
@end
@implementation GADRewardedAd (event)
/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
B4I* bi = [b4i_main new].bi;
[bi raiseEvent:nil event:@"rva_failedtoopen" params:nil];
}
/// Tells the delegate that the ad will present full screen content.
- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
B4I* bi = [b4i_main new].bi;
[bi raiseEvent:nil event:@"rva_adopened" params:nil];
}
/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
B4I* bi = [b4i_main new].bi;
[bi raiseEvent:nil event:@"rva_adclosed" params:nil];
}
#End If