-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
83 lines (64 loc) · 1.96 KB
/
code.txt
File metadata and controls
83 lines (64 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#import <GoogleMobileAds/GoogleMobileAds.h>
//Settings
#define APP_ID @"com.deezr.Deezer"
#define AD_UNIT_ID @"ca-app-pub-1138146631099272/1719831380"
#define SECONDS_BETWEEN_ADS 30.0
%hook NSBundle
- (id)objectForInfoDictionaryKey:(NSString*)key
{
if([key isEqualToString:@"GADApplicationIdentifier"])
{
return APP_ID;
}
if([key isEqualToString:@"GADIsAdManagerApp"])
{
return @YES;
}
return %orig;
}
%end
@interface UIViewController (GADInterstitialDelegate) <GADInterstitialDelegate>
@end
@interface UIViewController (Ads)
@property (nonatomic, retain) GADInterstitial *interstitial;
- (void)playAd;
@end
%hook UIViewController
%property (nonatomic, retain) GADInterstitial *interstitial;
%new
- (void)playAd
{
if(!self.interstitial)
{
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:AD_UNIT_ID];
self.interstitial.delegate = self;
}
GADRequest *request = [GADRequest request];
[self.interstitial loadRequest:request];
}
%new
- (void)interstitialDidReceiveAd:(GADInterstitial*)ad
{
[self.interstitial presentFromRootViewController:self];
}
%end
static NSTimer* adTimer;
void playAd()
{
[[UIApplication sharedApplication].keyWindow.rootViewController playAd];
}
void appLoaded(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
[[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status)
{
playAd(); //Play initial ad
adTimer = [NSTimer scheduledTimerWithTimeInterval:SECONDS_BETWEEN_ADS target:[NSBlockOperation blockOperationWithBlock:^
{
playAd(); //Repeat ad after time interval
}] selector:@selector(main) userInfo:nil repeats:YES];
}];
}
%ctor
{
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), NULL, appLoaded, (CFStringRef)UIApplicationDidFinishLaunchingNotification, NULL, CFNotificationSuspensionBehaviorCoalesce);
}