Manos Chorianopoulos

Added sendDeviceInfoIfNecessary function

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -101,6 +101,7 @@
- (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;
// - (void)didReceiveNotification:(NSDictionary *)userInfo whileAppWasInState:(WLApplicationState)state;
- (void)didReceiveNotification:(NSDictionary *)payload;
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
@end
#endif /* MyApi_h */
......
......@@ -1610,4 +1610,9 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
[[Warply sharedService].pushManager didReceiveRemoteNotification:payload whileAppWasInState:WLApplicationStateClosed];
}
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken {
[[Warply sharedService].pushManager sendDeviceInfoIfNecessary:newDeviceToken];
}
@end
......
......@@ -201,10 +201,13 @@ typedef enum WLApplicationState : unsigned int{
@discussion This function is internal and only used by Warply service.
*/
- (void)sendDeviceInfoIfNecessary;
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken;
- (void)sendDeviceInfo;
- (void)sendDeviceInfo:(NSString *)newDeviceToken;
- (NSDictionary *)deviceInfo;
- (NSDictionary *)deviceInfo:(NSString *)newDeviceToken;
- (NSDictionary *)applicationData;
......
......@@ -371,9 +371,9 @@ static const char* jailbreak_apps[] =
NSLog(@"application_data_has_changed: %@",application_data_has_changed);
NSLog(@"_isMissingDeviceInfo: %@",_isMissingDeviceInfo);
// if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
[self sendDeviceInfo];
// }
}
}
///////////////////////////////////////////////////////////////////////////////
......@@ -395,6 +395,55 @@ static const char* jailbreak_apps[] =
}
///////////////////////////////////////////////////////////////////////////////
// TODO: Check
- (void)sendDeviceInfoIfNecessary:(NSString *)newDeviceToken
{
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:newDeviceToken] isEqualToDictionary:oldDeviceInfo];
NSDictionary *oldApplicationData = [defaults objectForKey:WL_APPLICATION_DATA];
BOOL application_data_has_changed = ![[self applicationData] isEqualToDictionary:oldApplicationData];
// TODO: DELETE
NSLog(@"oldDeviceInfo: %@",oldDeviceInfo);
NSLog(@"device_info_has_changed: %@",device_info_has_changed);
NSLog(@"oldApplicationData: %@",oldApplicationData);
NSLog(@"application_data_has_changed: %@",application_data_has_changed);
NSLog(@"_isMissingDeviceInfo: %@",_isMissingDeviceInfo);
// if (device_info_has_changed || application_data_has_changed || _isMissingDeviceInfo) {
[self sendDeviceInfo:newDeviceToken];
// }
}
///////////////////////////////////////////////////////////////////////////////
- (void)sendDeviceInfo:(NSString *)newDeviceToken
{
WLEventSimple *deviceInfoEvent = [[WLEventSimple alloc] initWithType:@"device_info" andContext:[NSDictionary dictionaryWithObject:[self deviceInfo:newDeviceToken] 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:newDeviceToken] forKey:@"device_info"];
[defaults synchronize];
} failureBlock:nil];
}
///////////////////////////////////////////////////////////////////////////////
- (void)showItem:(WLInboxItem*)item
{
WLInboxItemViewController *itemViewController = [[WLInboxItemViewController alloc] initWithItem:item];
......@@ -527,6 +576,117 @@ static const char* jailbreak_apps[] =
}
///////////////////////////////////////////////////////////////////////////////
// TODO: Check
- (NSDictionary *)deviceInfo:(NSString *)newDeviceToken
{
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 (newDeviceToken.length != 0) {
[deviceInfo setValue:newDeviceToken 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
......
......@@ -5577,6 +5577,13 @@ public class swiftApi {
let instanceOfMyApi = MyApi()
instanceOfMyApi.didReceiveNotification(payload)
}
public func sendDeviceInfoIfNecessary(_ newDeviceToken: String) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.sendDeviceInfoIfNecessary(newDeviceToken)
}
}
......