Manos Chorianopoulos

Added sendDeviceInfoIfNecessary function

...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>1</integer> 10 + <integer>0</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> 7 <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
8 <dict> 8 <dict>
9 <key>orderHint</key> 9 <key>orderHint</key>
10 - <integer>0</integer> 10 + <integer>1</integer>
11 </dict> 11 </dict>
12 </dict> 12 </dict>
13 </dict> 13 </dict>
......
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
101 - (void)getMultilingualMerchantsAsync:(NSArray*)categories andDefaultShown:(NSNumber*)defaultShown andCenter:(NSNumber*)center andTags:(NSArray*)tags andUuid:(NSString*)uuid andDistance:(NSNumber*)distance parent_uuids:(NSArray*)parent_uuids :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; 101 - (void)getMultilingualMerchantsAsync:(NSArray*)categories andDefaultShown:(NSNumber*)defaultShown andCenter:(NSNumber*)center andTags:(NSArray*)tags andUuid:(NSString*)uuid andDistance:(NSNumber*)distance parent_uuids:(NSArray*)parent_uuids :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure;
102 // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state; 102 // - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
103 - (void)didReceiveNotification:(NSDictionary *)payload; 103 - (void)didReceiveNotification:(NSDictionary *)payload;
104 +- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
104 105
105 @end 106 @end
106 #endif /* MyApi_h */ 107 #endif /* MyApi_h */
......
...@@ -1610,4 +1610,9 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1610,4 +1610,9 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1610 [[Warply sharedService].pushManager didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed]; 1610 [[Warply sharedService].pushManager didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed];
1611 } 1611 }
1612 1612
1613 +- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken {
1614 +
1615 + [[Warply sharedService].pushManager sendDeviceInfoIfNecessary:newDeviceToken];
1616 +}
1617 +
1613 @end 1618 @end
......
...@@ -201,10 +201,13 @@ typedef enum WLApplicationState : unsigned int{ ...@@ -201,10 +201,13 @@ typedef enum WLApplicationState : unsigned int{
201 @discussion This function is internal and only used by Warply service. 201 @discussion This function is internal and only used by Warply service.
202 */ 202 */
203 - (void)sendDeviceInfoIfNecessary; 203 - (void)sendDeviceInfoIfNecessary;
204 +- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
204 205
205 - (void)sendDeviceInfo; 206 - (void)sendDeviceInfo;
207 +- (void)sendDeviceInfo:(NSString *)newDeviceToken;
206 208
207 - (NSDictionary *)deviceInfo; 209 - (NSDictionary *)deviceInfo;
210 +- (NSDictionary *)deviceInfo:(NSString *)newDeviceToken;
208 211
209 - (NSDictionary *)applicationData; 212 - (NSDictionary *)applicationData;
210 213
......
...@@ -371,9 +371,9 @@ static const char* jailbreak_apps[] = ...@@ -371,9 +371,9 @@ static const char* jailbreak_apps[] =
371 NSLog(@"application_data_has_changed: %@",application_data_has_changed); 371 NSLog(@"application_data_has_changed: %@",application_data_has_changed);
372 NSLog(@"_isMissingDeviceInfo: %@",_isMissingDeviceInfo); 372 NSLog(@"_isMissingDeviceInfo: %@",_isMissingDeviceInfo);
373 373
374 - // if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) { 374 + if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
375 [self sendDeviceInfo]; 375 [self sendDeviceInfo];
376 - // } 376 + }
377 } 377 }
378 378
379 /////////////////////////////////////////////////////////////////////////////// 379 ///////////////////////////////////////////////////////////////////////////////
...@@ -395,6 +395,55 @@ static const char* jailbreak_apps[] = ...@@ -395,6 +395,55 @@ static const char* jailbreak_apps[] =
395 } 395 }
396 396
397 /////////////////////////////////////////////////////////////////////////////// 397 ///////////////////////////////////////////////////////////////////////////////
398 +// TODO: Check
399 +- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken
400 +{
401 + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
402 + if ([defaults boolForKey:@"NBAPPUuidChanged"] == YES) {
403 + [defaults removeObjectForKey:@"device_info"];
404 + [defaults removeObjectForKey:WL_APPLICATION_DATA];
405 + [defaults synchronize];
406 +
407 + }
408 +
409 + NSDictionary *oldDeviceInfo = [defaults objectForKey:@"device_info"];
410 +
411 + BOOL device_info_has_changed = ![[self deviceInfo:newDeviceToken] isEqualToDictionary:oldDeviceInfo];
412 +
413 + NSDictionary *oldApplicationData = [defaults objectForKey:WL_APPLICATION_DATA];
414 + BOOL application_data_has_changed = ![[self applicationData] isEqualToDictionary:oldApplicationData];
415 +
416 + // TODO: DELETE
417 + NSLog(@"oldDeviceInfo: %@",oldDeviceInfo);
418 + NSLog(@"device_info_has_changed: %@",device_info_has_changed);
419 + NSLog(@"oldApplicationData: %@",oldApplicationData);
420 + NSLog(@"application_data_has_changed: %@",application_data_has_changed);
421 + NSLog(@"_isMissingDeviceInfo: %@",_isMissingDeviceInfo);
422 +
423 +// if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
424 + [self sendDeviceInfo:newDeviceToken];
425 +// }
426 +}
427 +
428 +///////////////////////////////////////////////////////////////////////////////
429 +- (void)sendDeviceInfo:(NSString *)newDeviceToken
430 +{
431 + WLEventSimple *deviceInfoEvent = [[WLEventSimple alloc] initWithType:@"device_info" andContext:[NSDictionary dictionaryWithObject:[self deviceInfo:newDeviceToken] forKey:@"device_info"]];
432 + [[Warply sharedService] addEvent:(WLEvent*)deviceInfoEvent priority:NO];
433 +
434 + WLEventSimple *applicationDataEvent = [[WLEventSimple alloc] initWithType:WL_APPLICATION_DATA andContext:[NSDictionary dictionaryWithObject:[self applicationData] forKey:WL_APPLICATION_DATA]];
435 + [[Warply sharedService] addEvent:(WLEvent*)applicationDataEvent priority:NO];
436 + _hasSentDeviceInfo = YES;
437 + _isMissingDeviceInfo = NO;
438 + [[Warply sharedService] sendAllEventsWithCompletionBlock:^{
439 + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
440 + [defaults setObject:[self applicationData] forKey:WL_APPLICATION_DATA];
441 + [defaults setObject:[self deviceInfo:newDeviceToken] forKey:@"device_info"];
442 + [defaults synchronize];
443 + } failureBlock:nil];
444 +}
445 +
446 +///////////////////////////////////////////////////////////////////////////////
398 - (void)showItem:(WLInboxItem*)item 447 - (void)showItem:(WLInboxItem*)item
399 { 448 {
400 WLInboxItemViewController *itemViewController = [[WLInboxItemViewController alloc] initWithItem:item]; 449 WLInboxItemViewController *itemViewController = [[WLInboxItemViewController alloc] initWithItem:item];
...@@ -527,6 +576,117 @@ static const char* jailbreak_apps[] = ...@@ -527,6 +576,117 @@ static const char* jailbreak_apps[] =
527 } 576 }
528 577
529 /////////////////////////////////////////////////////////////////////////////// 578 ///////////////////////////////////////////////////////////////////////////////
579 +// TODO: Check
580 +- (NSDictionary *)deviceInfo:(NSString *)newDeviceToken
581 +{
582 + CTTelephonyNetworkInfo *telephony = [[CTTelephonyNetworkInfo alloc] init];
583 + CTCarrier *carrier = telephony.subscriberCellularProvider;
584 + NSArray *prefLangs = [NSLocale preferredLanguages];
585 + NSUInteger count = [prefLangs count];
586 + NSString *langs = [NSString stringWithFormat:@"%@, %@, %@, %@, %@",
587 + (count > 0)?[prefLangs objectAtIndex:0]:@"-",
588 + (count > 1)?[prefLangs objectAtIndex:1]:@"-",
589 + (count > 2)?[prefLangs objectAtIndex:2]:@"-",
590 + (count > 3)?[prefLangs objectAtIndex:3]:@"-",
591 + (count > 4)?[prefLangs objectAtIndex:4]:@"-"];
592 +
593 + NSMutableDictionary *deviceInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
594 +#if (DEBUG == 1)
595 + @"true" , @"development",
596 +#else
597 + @"false" , @"development",
598 +#endif
599 + nil];
600 +
601 + if ([[[UIDevice currentDevice] systemName] length] != 0) {
602 + [deviceInfo setValue:[[UIDevice currentDevice] systemName] forKey:@"ios_system_name"];
603 + }
604 + if ([[[UIDevice currentDevice] systemVersion] length] != 0) {
605 + [deviceInfo setValue:[[UIDevice currentDevice] systemVersion] forKey:@"ios_system_version"];
606 + }
607 + if ([[[UIDevice currentDevice] platformString] length] != 0) {
608 + [deviceInfo setValue:[[UIDevice currentDevice] platformString] forKey:@"ios_model"];
609 + }
610 + if ([[UIDevice currentDevice] platform].length != 0) {
611 + [deviceInfo setValue:[[UIDevice currentDevice] platform] forKey:@"ios_device_model"];
612 + }
613 + if ([[UIDevice currentDevice] deviceFamilyString].length != 0) {
614 + [deviceInfo setValue:[[UIDevice currentDevice] deviceFamilyString] forKey:@"device_family"];
615 + }
616 + if (carrier.carrierName.length != 0) {
617 + [deviceInfo setValue:carrier.carrierName forKey:@"carrier_name"];
618 + }
619 + if (carrier.isoCountryCode.length != 0) {
620 + [deviceInfo setValue:carrier.isoCountryCode forKey:@"ios_iso_country_code"];
621 + }
622 + if ([[[UIDevice currentDevice] localizedModel] length] != 0) {
623 + [deviceInfo setValue:[[UIDevice currentDevice] localizedModel] forKey:@"ios_localized_model"];
624 + }
625 + if ([[[NSLocale currentLocale] localeIdentifier] length] != 0) {
626 + [deviceInfo setValue:[[NSLocale currentLocale] localeIdentifier] forKey:@"ios_locale"];
627 + }
628 + if (langs.length != 0) {
629 + [deviceInfo setValue:langs forKey:@"ios_languages"];
630 + }
631 +
632 + [deviceInfo setValue:@"apple" forKey:@"vendor"];
633 +
634 + [deviceInfo setValue:@"ios" forKey:@"platform"];
635 +
636 + [deviceInfo setValue:[[UIDevice currentDevice] systemVersion] forKey:@"os_version"];
637 +
638 + [deviceInfo setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"unique_device_id"];
639 +
640 + [deviceInfo setValue:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:@"advertising_id"];
641 +
642 + [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"];
643 +
644 +#if (WARPLY_UDID_ENABLED == 1)
645 + if ([[UIDevice currentDevice] respondsToSelector:@selector(uniqueIdentifier)]) {
646 + [device_info setValue:[UIDevice currentDevice].uniqueIdentifier forKey:@"ios_unique_identifier"];
647 + }
648 +#endif
649 +
650 + [deviceInfo setValue:[self isJailBroken]?[NSNumber numberWithBool:YES] : [NSNumber numberWithBool:NO] forKey:@"ios_is_jailbroken_phone"];
651 +
652 + if (newDeviceToken.length != 0) {
653 + [deviceInfo setValue:newDeviceToken forKey:@"device_token"];
654 + }
655 +
656 + [deviceInfo setValue:[NSNumber numberWithBool:!self.apsRegistrationError] forKey:@"ios_aps_entitlement_valid"];
657 +
658 + NSUInteger rntypes;
659 +
660 + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
661 + [deviceInfo setValue:[NSNumber numberWithInt:_notificationOptions] forKey:@"notification_types"];
662 + } else {
663 + [deviceInfo setValue:[NSNumber numberWithInt:_notificationTypes] forKey:@"notification_types"];
664 + }
665 +
666 + if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
667 +#pragma clang diagnostic push
668 +#pragma clang diagnostic ignored "-Wdeprecated-declarations"
669 + rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
670 +#pragma clang diagnostic pop
671 + }else{
672 + rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
673 + }
674 +
675 + [deviceInfo setValue:[NSNumber numberWithInteger:rntypes] forKey:@"user_enabled_notification_types"];
676 +
677 + // NSMutableDictionary *apple_uuids = [NSMutableDictionary dictionaryWithCapacity:2];
678 + [deviceInfo setValue:[NSNumber numberWithBool:[ASIdentifierManager sharedManager].advertisingTrackingEnabled] forKey:@"advertising_tracking_enabled"];
679 + [deviceInfo setValue:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:@"advertising_identifier"];
680 + [deviceInfo setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"identifier_for_vendor"];
681 +
682 + // [deviceInfo setValue:apple_uuids forKey: @"ios_uuids"];
683 +
684 + NSLog(@"%@", deviceInfo);
685 +
686 + return deviceInfo;
687 +}
688 +
689 +///////////////////////////////////////////////////////////////////////////////
530 - (NSDictionary *)applicationData 690 - (NSDictionary *)applicationData
531 { 691 {
532 //Application Data Hack 692 //Application Data Hack
......
...@@ -5579,4 +5579,11 @@ public class swiftApi { ...@@ -5579,4 +5579,11 @@ public class swiftApi {
5579 } 5579 }
5580 5580
5581 5581
5582 + public func sendDeviceInfoIfNecessary(_ newDeviceToken: String) -> Void {
5583 +
5584 + let instanceOfMyApi = MyApi()
5585 + instanceOfMyApi.sendDeviceInfoIfNecessary(newDeviceToken)
5586 + }
5587 +
5588 +
5582 } 5589 }
......