Skip to content

Commit

Permalink
[TIMOB-24730] (6_2_X) iOS: Remove old statements (e.g. ![TiUtils isIO…
Browse files Browse the repository at this point in the history
…S8OrGreater]) (#9316)

* [TIMOB-24730]: iOS: Remove old statements (e.g. ![TiUtils isIOS8OrGreater])

# Conflicts:
#	iphone/Classes/ContactsModule.m
#	iphone/Classes/TiApp.m
#	iphone/Classes/TiUIAlertDialogProxy.m
#	iphone/Classes/TiUITabGroup.m
#	iphone/Classes/TiUITableView.m

* [TIMOB-24729]:Indentation fix

* [TIMOB-24730]: Minor fixes

# Conflicts:
#	iphone/Classes/TiUIAlertDialogProxy.m

* Update ContactsModule.m
# Conflicts:
#	iphone/Classes/ContactsModule.m

* [TIMOB-24730]: Minor fixes

* Update ContactsModule.m

* Update ContactsModule.m

* Update ContactsModule.m
  • Loading branch information
hansemannn committed Aug 22, 2017
1 parent e1ed6d1 commit b58f976
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 725 deletions.
6 changes: 0 additions & 6 deletions iphone/Classes/AppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ -(void)keyboardFrameChanged:(NSNotification*) notification
NSDictionary *userInfo = [notification userInfo];
NSNumber* duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
CGRect keyboardEndFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
if (![TiUtils isIOS8OrGreater]) {
// window for keyboard
UIWindow *keyboardWindow = [[[UIApplication sharedApplication] windows] lastObject];

keyboardEndFrame = [keyboardWindow convertRect:keyboardEndFrame fromWindow:nil];
}

NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:
[TiUtils rectToDictionary:keyboardEndFrame], @"keyboardFrame",
Expand Down
21 changes: 9 additions & 12 deletions iphone/Classes/CalendarModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,17 @@ -(TiCalendarCalendar*)getCalendarById:(id)arg
return nil;
}
EKCalendar* calendar_ = NULL;
if ([TiUtils isIOS8OrGreater]) {
//Instead of getting calendar by identifier, have to get all and check for match
//not optimal but best way to fix non existing shared calendar error
NSArray *allCalendars = [ourStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *cal in allCalendars) {
if ([cal.calendarIdentifier isEqualToString:arg]) {
calendar_ = cal;
break;
}

//Instead of getting calendar by identifier, have to get all and check for match
//not optimal but best way to fix non existing shared calendar error
NSArray *allCalendars = [ourStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *cal in allCalendars) {
if ([cal.calendarIdentifier isEqualToString:arg]) {
calendar_ = cal;
break;
}
}
else {
calendar_ = [ourStore calendarWithIdentifier:arg];
}

if (calendar_ == NULL) {
return NULL;
}
Expand Down
76 changes: 43 additions & 33 deletions iphone/Classes/ContactsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ -(void)showContacts:(id)args
selectedPropertyCallback = [[args objectForKey:@"selectedProperty"] retain];
if ([TiUtils isIOS9OrGreater]) {
contactPicker = [[CNContactPickerViewController alloc] init];
[contactPicker setDelegate:self];
if (selectedPropertyCallback == nil) {
contactPicker.predicateForSelectionOfProperty = [NSPredicate predicateWithValue:NO];
}
[contactPicker setDelegate:self];
if (selectedPropertyCallback == nil) {
contactPicker.predicateForSelectionOfProperty = [NSPredicate predicateWithValue:NO];
}

if (selectedPersonCallback == nil) {
contactPicker.predicateForSelectionOfContact = [NSPredicate predicateWithValue:NO];
}
Expand Down Expand Up @@ -391,11 +391,11 @@ -(void)showContacts:(id)args
if (selectedPropertyCallback == nil) {
[picker setPredicateForSelectionOfProperty:[NSPredicate predicateWithValue:NO]];
}
if (selectedPersonCallback == nil) {
[picker setPredicateForSelectionOfPerson:[NSPredicate predicateWithValue:NO]];
}

animated = [TiUtils boolValue:@"animated" properties:args def:YES];

NSArray* fields = [args objectForKey:@"fields"];
Expand All @@ -418,60 +418,65 @@ -(void)showContacts:(id)args

// OK to do outside main thread
-(TiContactsPerson*)getPersonByID:(id)arg
{
{
if ([TiUtils isIOS9OrGreater]) {
DebugLog(@"This method is removed for iOS9 and greater.");
return nil;
}
ENSURE_SINGLE_ARG(arg, NSObject)

ENSURE_SINGLE_ARG(arg, NSString)

__block int idNum = [TiUtils intValue:arg];
__block BOOL validId = NO;

TiThreadPerformOnMainThread(^{
ABAddressBookRef ourAddressBook = [self addressBook];
if (ourAddressBook == NULL) {
return;
}
ABRecordRef record = NULL;
record = ABAddressBookGetPersonWithRecordID(ourAddressBook, idNum);
if (record != NULL)
{
if (record != NULL) {
validId = YES;
}
}, YES);
if (validId == YES)
{
}, YES);

if (validId == YES) {
return [[[TiContactsPerson alloc] _initWithPageContext:[self executionContext] recordId:idNum module:self] autorelease];
}

return NULL;
}

-(TiContactsGroup*)getGroupByID:(id)arg
{
ENSURE_SINGLE_ARG(arg, NSObject)

if ([TiUtils isIOS9OrGreater]) {
DebugLog(@"This method is removed for iOS9 and greater.");
return nil;
}
ENSURE_SINGLE_ARG(arg, NSObject)

__block int idNum = [TiUtils intValue:arg];
__block BOOL validId = NO;

TiThreadPerformOnMainThread(^{
ABAddressBookRef ourAddressBook = [self addressBook];
if (ourAddressBook == NULL) {
return;
}
ABRecordRef record = NULL;
record = ABAddressBookGetGroupWithRecordID(ourAddressBook, idNum);
if (record != NULL)
{
if (record != NULL) {
validId = YES;
}
}, YES);
if (validId == YES)
{
}, YES);

if (validId == YES) {
return [[[TiContactsGroup alloc] _initWithPageContext:[self executionContext] recordId:idNum module:self] autorelease];
}
return NULL;

return NULL;
}

//New in iOS9
Expand All @@ -481,12 +486,15 @@ -(TiContactsPerson*)getPersonByIdentifier:(id)arg
DebugLog(@"This method is only for iOS9 and greater.");
return nil;
}

if (![NSThread isMainThread]) {
__block id result;
TiThreadPerformOnMainThread(^{result = [[self getPersonByIdentifier:arg] retain];}, YES);
return [result autorelease];
}

ENSURE_SINGLE_ARG(arg, NSString)

CNContactStore *ourContactStore = [self contactStore];
if (ourContactStore == NULL) {
return nil;
Expand All @@ -497,13 +505,14 @@ -(TiContactsPerson*)getPersonByIdentifier:(id)arg
if (error) {
return nil;
}

return [[[TiContactsPerson alloc] _initWithPageContext:[self executionContext]
contactId:(CNMutableContact *)contact
module:self
observer:self] autorelease];
}

//New in iOS9
// New in iOS9
-(TiContactsGroup*)getGroupByIdentifier:(id)arg
{
if (![TiUtils isIOS9OrGreater]) {
Expand Down Expand Up @@ -592,11 +601,12 @@ -(NSArray*)getPeopleWithName:(id)arg

-(NSArray*)getAllPeople:(id)unused
{
if (![NSThread isMainThread]) {
__block id result = nil;
TiThreadPerformOnMainThread(^{result = [[self getAllPeople:unused] retain];}, YES);
return [result autorelease];
}
if (![NSThread isMainThread]) {
__block id result = nil;
TiThreadPerformOnMainThread(^{result = [[self getAllPeople:unused] retain];}, YES);

return [result autorelease];
}

if ([TiUtils isIOS9OrGreater]) {
CNContactStore *ourContactStore = [self contactStore];
Expand All @@ -612,13 +622,14 @@ -(NSArray*)getAllPeople:(id)unused
TiContactsPerson* person = [[[TiContactsPerson alloc] _initWithPageContext:[self executionContext] contactId:(CNMutableContact*)contact module:self observer:self] autorelease];
[peopleRefs addObject:person];
}];
RELEASE_TO_NIL(fetchRequest)
if (success) {

RELEASE_TO_NIL(fetchRequest)

if (success) {
NSArray *people = [NSArray arrayWithArray:peopleRefs];
RELEASE_TO_NIL(peopleRefs)
return people;
}
else {
} else {
DebugLog(@"%@", [TiUtils messageFromError:error]);
RELEASE_TO_NIL(peopleRefs)
return nil;
Expand All @@ -642,9 +653,8 @@ -(NSArray*)getAllPeople:(id)unused
[people addObject:person];
}
CFRelease(peopleRefs);
return people;


return people;
}

-(NSArray*)getAllGroups:(id)unused
Expand Down
60 changes: 16 additions & 44 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,22 +304,14 @@ -(CLLocationManager*)locationManager
}
locationManager.headingFilter = heading;

if ([TiUtils isIOS8OrGreater]) {
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
[locationManager requestAlwaysAuthorization];
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
[locationManager requestWhenInUseAuthorization];
} else {
NSLog(@"[ERROR] The keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription are not defined in your tiapp.xml. Starting with iOS8 this is required.");
}
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
[locationManager requestAlwaysAuthorization];
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
[locationManager requestWhenInUseAuthorization];
} else {
if (purpose != nil) {
DebugLog(@"[WARN] The Ti.Geolocation.purpose property is deprecated. On iOS6 and above include the NSLocationUsageDescription key in your Info.plist");
if ([locationManager respondsToSelector:@selector(setPurpose:)]) {
[locationManager performSelector:@selector(setPurpose:) withObject:purpose];
}
}
NSLog(@"[ERROR] The keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription are not defined in your tiapp.xml. Starting with iOS8 this is required.");
}

//This is set to NO by default for > iOS9.
if ([TiUtils isIOS9OrGreater]) {
locationManager.allowsBackgroundLocationUpdates = allowsBackgroundLocationUpdates;
Expand Down Expand Up @@ -794,18 +786,12 @@ -(void)restart:(id)arg

-(NSNumber*)AUTHORIZATION_ALWAYS
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(kCLAuthorizationStatusAuthorizedAlways);
}
return NUMINT(0);
return NUMINT(kCLAuthorizationStatusAuthorizedAlways);
}

-(NSNumber*)AUTHORIZATION_WHEN_IN_USE
{
if ([TiUtils isIOS8OrGreater]) {
return NUMINT(kCLAuthorizationStatusAuthorizedWhenInUse);
}
return NUMINT(0);
return NUMINT(kCLAuthorizationStatusAuthorizedWhenInUse);
}

-(CLLocationManager*)locationPermissionManager
Expand All @@ -822,14 +808,10 @@ -(NSNumber*)hasLocationPermissions:(id)args
{
BOOL locationServicesEnabled = [CLLocationManager locationServicesEnabled];
CLAuthorizationStatus currentPermissionLevel = [CLLocationManager authorizationStatus];
if ([TiUtils isIOS8OrGreater]) {
id value = [args objectAtIndex:0];
ENSURE_TYPE(value, NSNumber);
CLAuthorizationStatus requestedPermissionLevel = [TiUtils intValue: value];
return NUMBOOL(locationServicesEnabled && currentPermissionLevel == requestedPermissionLevel);
} else {
return NUMBOOL(locationServicesEnabled && currentPermissionLevel == kCLAuthorizationStatusAuthorized);
}
id value = [args objectAtIndex:0];
ENSURE_TYPE(value, NSNumber);
CLAuthorizationStatus requestedPermissionLevel = [TiUtils intValue: value];
return NUMBOOL(locationServicesEnabled && currentPermissionLevel == requestedPermissionLevel);
}

-(void)requestAuthorization:(id)value
Expand Down Expand Up @@ -863,14 +845,6 @@ - (void)requestLocationPermissioniOS7:(id)args {

-(void)requestLocationPermissions:(id)args
{
if (![TiUtils isIOS8OrGreater]) {
// It is required that delegate is created and permission is presented in main thread.
TiThreadPerformOnMainThread(^{
[self requestLocationPermissioniOS7:args];
}, NO);
return;
}

id value = [args objectAtIndex:0];
ENSURE_TYPE(value, NSNumber);

Expand Down Expand Up @@ -969,12 +943,10 @@ -(NSDictionary*)locationDictionary:(CLLocation*)newLocation;
[NSNumber numberWithLongLong:(long long)([[newLocation timestamp] timeIntervalSince1970] * 1000)],@"timestamp",
nil];

if ([TiUtils isIOS8OrGreater]) {
NSDictionary *floor = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:[[newLocation floor] level]],@"level",
nil];
[data setObject:floor forKey:@"floor"];
}
NSDictionary *floor = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:[[newLocation floor] level]],@"level",
nil];
[data setObject:floor forKey:@"floor"];

return data;
}
Expand Down

0 comments on commit b58f976

Please sign in to comment.