WLPushManager.m
24.5 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/*
Copyright 2010-2016 Warply Inc. All rights reserved.
Redistribution and use in source and binary forms, without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binaryform must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "WLPushManager.h"
#import "WLGlobals.h"
#import "WLEvent.h"
#import "Warply.h"
#import "WLBaseItem.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
#import "WLInboxItem.h"
#import "WLInboxItemViewController.h"
#import <AdSupport/AdSupport.h>
#import "WLUtils.h"
#import "UIViewController+WLAdditions.h"
///////////////////////////////////////////////////////////////////////////////
@interface WLPushManager()
{
//Push
NSMutableDictionary *_actionHandlerDict;
}
@property (nonatomic) BOOL apsRegistrationError;
- (BOOL)isJailBroken;
@end
@implementation WLPushManager
@synthesize deviceToken = _deviceToken;
@synthesize notificationTypes = _notificationTypes;
@synthesize notificationOptions = _notificationOptions;
///////////////////////////////////////////////////////////////////////////////
static const char* jailbreak_apps[] =
{
"/Applications/Cydia.app",
"/Applications/limera1n.app",
"/Applications/greenpois0n.app",
"/Applications/blackra1n.app",
"/Applications/blacksn0w.app",
"/Applications/redsn0w.app",
NULL,
};
#pragma mark - Initialization
///////////////////////////////////////////////////////////////////////////////
- (id)init
{
self = [super init];
if (self) {
_actionHandlerDict = [[NSMutableDictionary alloc] init];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_notificationTypes = UIRemoteNotificationTypeNone;
#pragma clang diagnostic pop
_apsRegistrationError = FALSE;
}
return self;
}
#pragma mark - Properties
///////////////////////////////////////////////////////////////////////////////
- (void)setDeviceToken:(NSString *)aDeviceToken
{
if ([_deviceToken isEqualToString:aDeviceToken] == YES)
return;
_deviceToken = [aDeviceToken copy];
//Save new valuetodo
if ((_deviceToken != (NSString *)[NSNull null]) && (_deviceToken.length > 0))
[WLKeychain setString:_deviceToken forKey:@"NBDeviceToken"];
else
[WLKeychain deleteStringForKey:@"NBDeviceToken"];
}
#pragma mark - Public Methods
///////////////////////////////////////////////////////////////////////////////
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types
{
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
_notificationTypes = types;
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:_notificationTypes];
#pragma clang diagnostic pop
}
}
}
#pragma clang diagnostic pop
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(@"User Info : %@",notification.request.content.userInfo);
WLApplicationState warplyAppState;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
warplyAppState = WLApplicationStateActive;
[self didReceiveRemoteNotification:notification.request.content.userInfo whileAppWasInState:warplyAppState];
} else {
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
}
//Called to let your app know which action was selected by the user for a given notification.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
NSString *category = response.notification.request.content.userInfo[@"aps"][@"category"];
if (category != [NSNull null] && [category isEqualToString:@"shareCategory"]) {
if ([response.actionIdentifier isEqualToString:@"share_identifier"]) {
NSString *title = response.notification.request.content.userInfo[@"data"][@"text"];
NSString *url = response.notification.request.content.userInfo[@"data"][@"url"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SharedCategory"];
[[NSUserDefaults standardUserDefaults] setObject:title forKey:@"SharedTitle"];
[[NSUserDefaults standardUserDefaults] setObject:url forKey:@"SharedUrl"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
} else if (category != [NSNull null] && [category isEqualToString:@"favoriteCategory"]) {
if ([response.actionIdentifier isEqualToString:@"favorite_identifier"]) {
NSLog(@"favorite_identifier");
}
} else if (category != [NSNull null] && [category isEqualToString:@"bookCategory"]) {
if ([response.actionIdentifier isEqualToString:@"book_identifier"]) {
NSString *bookID = response.notification.request.content.userInfo[@"data"][@"id"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"BookCategory"];
[[NSUserDefaults standardUserDefaults] setObject:bookID forKey:@"BookID"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"DidReceiveNotificaitonWithAction" object:nil];
WLApplicationState warplyAppState;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
warplyAppState = WLApplicationStateActive;
else
warplyAppState = WLApplicationStateBackground;
[self didReceiveRemoteNotification:response.notification.request.content.userInfo whileAppWasInState:warplyAppState];
completionHandler();
}
- (void)registerForRemoteNotifications{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
_notificationOptions = UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}];
} else {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
_notificationTypes = UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge;
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_notificationTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:_notificationTypes];
#pragma clang diagnostic pop
}
}
}
///////////////////////////////////////////////////////////////////////////////
- (void)didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
WLLOG(@"LAUNCH OPTIONS: %@", launchOptions);
NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (payload == nil)
return;
if ([payload valueForKey:@"_a"] == nil) {
// The push was sent from another push service
return;
}
[self didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed];
}
///////////////////////////////////////////////////////////////////////////////
- (void)didReceiveRemoteNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state
{
if ([userInfo valueForKey:@"_a"] == nil) {
// The push was sent from another push service
return;
}
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
WLLOG(@"Did receive push: %@", jsonString);
WLInboxItem *inboxItem = [[WLInboxItem alloc] initWithAttributes:userInfo] ;
// [WLAnalyticsManager logUserReceivedPush:inboxItem];
if (state != WLApplicationStateActive) {
[WLAnalyticsManager logUserEngagedPush:inboxItem];
}
if (inboxItem.action != 0) {
[self.customPushHanlder didReceiveRemoteNotification:userInfo whileAppWasInState:state];
return;
}
switch (state) {
case WLApplicationStateActive:
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]];
[alert addButtonWithTitle:NSLocalizedString(@"Close", @"Warply")];
[alert addButtonWithTitle:NSLocalizedString(@"View", @"Warply")];
[alert setDelegate:self];
[alert show];
self.pendingItem = inboxItem;
break;
}
case WLApplicationStateBackground:
{
[self showItem:inboxItem];
break;
}
case WLApplicationStateClosed:
self.pendingItem = inboxItem;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
WLApplicationState warplyAppState;
if (application.applicationState == UIApplicationStateActive)
warplyAppState = WLApplicationStateActive;
else
warplyAppState = WLApplicationStateBackground;
[self didReceiveRemoteNotification:userInfo whileAppWasInState:warplyAppState];
}
///////////////////////////////////////////////////////////////////////////////
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
WLLOG(@"DEVICE TOKEN: %@", deviceToken);
if (SYSTEM_VERSION_LESS_THAN(@"13.0")) {
self.deviceToken = [[[deviceToken.description stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
} else {
NSUInteger dataLength = deviceToken.length;
const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes;
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (NSInteger index = 0; index < dataLength; ++index) {
[hexString appendFormat:@"%02x", dataBuffer[index]];
}
self.deviceToken = [hexString copy];
}
[self sendDeviceInfoIfNecessary];
}
///////////////////////////////////////////////////////////////////////////////
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
WLLOG(@"DEVICE TOKEN: FAILED. Error:%@", [error localizedDescription]);
self.deviceToken = nil;
if (error.code == 3000 || error.code == 3010)
self.apsRegistrationError = TRUE;
[self sendDeviceInfoIfNecessary];
}
///////////////////////////////////////////////////////////////////////////////
- (void)resetBadge
{
UIApplication *application = [UIApplication sharedApplication];
[application setApplicationIconBadgeNumber:1];
[application setApplicationIconBadgeNumber:0];
}
///////////////////////////////////////////////////////////////////////////////
- (BOOL)handlePendingNotification
{
if (self.pendingItem == nil)
return NO;
// make sure you call this in your handler to let the server know the user
// engaged with your notification
WLInboxItem *inboxItem = [[WLInboxItem alloc] initWithItem:self.pendingItem];
[self showItem:inboxItem];
self.pendingItem = nil;
return YES;
}
///////////////////////////////////////////////////////////////////////////////
- (void)sendDeviceInfoIfNecessary
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:@"NBAPPUuidChanged"] == YES) {
[defaults removeObjectForKey:@"device_info"];
[defaults removeObjectForKey:WL_APPLICATION_DATA];
[defaults synchronize];
}
NSDictionary *oldDeviceInfo = [defaults objectForKey:@"device_info"];
BOOL device_info_has_changed = ![[self deviceInfo] isEqualToDictionary:oldDeviceInfo];
NSDictionary *oldApplicationData = [defaults objectForKey:WL_APPLICATION_DATA];
BOOL application_data_has_changed = ![[self applicationData] isEqualToDictionary:oldApplicationData];
if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
[self sendDeviceInfo];
}
}
///////////////////////////////////////////////////////////////////////////////
- (void)sendDeviceInfo
{
WLEventSimple *deviceInfoEvent = [[WLEventSimple alloc] initWithType:@"device_info" andContext:[NSDictionary dictionaryWithObject:[self deviceInfo] forKey:@"device_info"]];
[[Warply sharedService] addEvent:(WLEvent*)deviceInfoEvent priority:NO];
WLEventSimple *applicationDataEvent = [[WLEventSimple alloc] initWithType:WL_APPLICATION_DATA andContext:[NSDictionary dictionaryWithObject:[self applicationData] forKey:WL_APPLICATION_DATA]];
[[Warply sharedService] addEvent:(WLEvent*)applicationDataEvent priority:NO];
_hasSentDeviceInfo = YES;
_isMissingDeviceInfo = NO;
[[Warply sharedService] sendAllEventsWithCompletionBlock:^{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[self applicationData] forKey:WL_APPLICATION_DATA];
[defaults setObject:[self deviceInfo] forKey:@"device_info"];
[defaults synchronize];
} failureBlock:nil];
}
///////////////////////////////////////////////////////////////////////////////
- (void)showItem:(WLInboxItem*)item
{
WLInboxItemViewController *itemViewController = [[WLInboxItemViewController alloc] initWithItem:item];
UINavigationController *newModalController = [[UINavigationController alloc] initWithRootViewController:itemViewController];
newModalController.navigationBarHidden = YES;
newModalController.toolbarHidden = NO;
UIViewController *existingModalController = [[UIApplication sharedApplication].delegate.window.rootViewController topModalViewController];
if (existingModalController == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"WL_Warning" message:@"You have to set the mainWindow.rootViewController in order for offer views to be presented properly." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
[existingModalController presentViewController:newModalController animated:YES completion:nil];
}
///////////////////////////////////////////////////////////////////////////////
- (NSDictionary *)deviceInfo
{
CTTelephonyNetworkInfo *telephony = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = telephony.subscriberCellularProvider;
NSArray *prefLangs = [NSLocale preferredLanguages];
NSUInteger count = [prefLangs count];
NSString *langs = [NSString stringWithFormat:@"%@, %@, %@, %@, %@",
(count > 0)?[prefLangs objectAtIndex:0]:@"-",
(count > 1)?[prefLangs objectAtIndex:1]:@"-",
(count > 2)?[prefLangs objectAtIndex:2]:@"-",
(count > 3)?[prefLangs objectAtIndex:3]:@"-",
(count > 4)?[prefLangs objectAtIndex:4]:@"-"];
NSMutableDictionary *deviceInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#if (DEBUG == 1)
@"true" , @"development",
#else
@"false" , @"development",
#endif
nil];
if ([[[UIDevice currentDevice] systemName] length] != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] systemName] forKey:@"ios_system_name"];
}
if ([[[UIDevice currentDevice] systemVersion] length] != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] systemVersion] forKey:@"ios_system_version"];
}
if ([[[UIDevice currentDevice] platformString] length] != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] platformString] forKey:@"ios_model"];
}
if ([[UIDevice currentDevice] platform].length != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] platform] forKey:@"ios_device_model"];
}
if ([[UIDevice currentDevice] deviceFamilyString].length != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] deviceFamilyString] forKey:@"device_family"];
}
if (carrier.carrierName.length != 0) {
[deviceInfo setValue:carrier.carrierName forKey:@"carrier_name"];
}
if (carrier.isoCountryCode.length != 0) {
[deviceInfo setValue:carrier.isoCountryCode forKey:@"ios_iso_country_code"];
}
if ([[[UIDevice currentDevice] localizedModel] length] != 0) {
[deviceInfo setValue:[[UIDevice currentDevice] localizedModel] forKey:@"ios_localized_model"];
}
if ([[[NSLocale currentLocale] localeIdentifier] length] != 0) {
[deviceInfo setValue:[[NSLocale currentLocale] localeIdentifier] forKey:@"ios_locale"];
}
if (langs.length != 0) {
[deviceInfo setValue:langs forKey:@"ios_languages"];
}
[deviceInfo setValue:@"apple" forKey:@"vendor"];
[deviceInfo setValue:@"ios" forKey:@"platform"];
[deviceInfo setValue:[[UIDevice currentDevice] systemVersion] forKey:@"os_version"];
[deviceInfo setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"unique_device_id"];
[deviceInfo setValue:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:@"advertising_id"];
[deviceInfo setValue:[NSString stringWithFormat:@"%.0fx%.0f",([UIScreen mainScreen].bounds.size.width * [[UIScreen mainScreen] scale]),([UIScreen mainScreen].bounds.size.height * [[UIScreen mainScreen] scale])] forKey:@"screen_resolution"];
#if (WARPLY_UDID_ENABLED == 1)
if ([[UIDevice currentDevice] respondsToSelector:@selector(uniqueIdentifier)]) {
[device_info setValue:[UIDevice currentDevice].uniqueIdentifier forKey:@"ios_unique_identifier"];
}
#endif
[deviceInfo setValue:[self isJailBroken]?[NSNumber numberWithBool:YES] : [NSNumber numberWithBool:NO] forKey:@"ios_is_jailbroken_phone"];
if (_deviceToken.length != 0) {
[deviceInfo setValue:_deviceToken forKey:@"device_token"];
}
[deviceInfo setValue:[NSNumber numberWithBool:!self.apsRegistrationError] forKey:@"ios_aps_entitlement_valid"];
NSUInteger rntypes;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
[deviceInfo setValue:[NSNumber numberWithInt:_notificationOptions] forKey:@"notification_types"];
} else {
[deviceInfo setValue:[NSNumber numberWithInt:_notificationTypes] forKey:@"notification_types"];
}
if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
#pragma clang diagnostic pop
}else{
rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
}
[deviceInfo setValue:[NSNumber numberWithInteger:rntypes] forKey:@"user_enabled_notification_types"];
// NSMutableDictionary *apple_uuids = [NSMutableDictionary dictionaryWithCapacity:2];
[deviceInfo setValue:[NSNumber numberWithBool:[ASIdentifierManager sharedManager].advertisingTrackingEnabled] forKey:@"advertising_tracking_enabled"];
[deviceInfo setValue:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:@"advertising_identifier"];
[deviceInfo setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"identifier_for_vendor"];
// [deviceInfo setValue:apple_uuids forKey: @"ios_uuids"];
NSLog(@"%@", deviceInfo);
return deviceInfo;
}
///////////////////////////////////////////////////////////////////////////////
- (NSDictionary *)applicationData
{
//Application Data Hack
NSBundle *mainBundle = [NSBundle mainBundle];
NSMutableDictionary *applicationData = [NSMutableDictionary dictionaryWithCapacity:3];
if ([Warply get].length != 0) {
[applicationData setValue:[Warply get] forKey:@"sdk_version"];
}
NSString *CFBundleIdentifier = [mainBundle objectForInfoDictionaryKey:@"CFBundleIdentifier"];
if (CFBundleIdentifier.length != 0) {
[applicationData setValue:CFBundleIdentifier forKey:@"bundle_identifier"];
}
NSString *CFBundleShortVersionString = [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
if (CFBundleShortVersionString.length != 0) {
[applicationData setValue:CFBundleShortVersionString forKey:@"app_version"];
}
NSString *CFBundleVersion = [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
if (CFBundleVersion.length != 0) {
[applicationData setValue:CFBundleVersion forKey:@"app_build"];
}
return applicationData;
}
#pragma mark - Private Methods
///////////////////////////////////////////////////////////////////////////////
- (BOOL)isJailBroken
{
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
// This key-value pair should not be in the pinfo file. If it is, we can be reasonably sure that the app has been compromised.
if ([info objectForKey: @"SignerIdentity"] != nil)
return YES;
// Now check for known jailbreak apps. If we encounter one, the device is jailbroken.
for (int i = 0; jailbreak_apps[i] != NULL; ++i)
{
if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithUTF8String:jailbreak_apps[i]]])
return YES;
}
return NO;
}
#pragma mark - UIAlertViewDelegate
///////////////////////////////////////////////////////////////////////////////
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[WLAnalyticsManager logUserEngagedPush:self.pendingItem];
[self handlePendingNotification];
}
}
@end