diff --git a/iOSMDMAgent/AppDelegate.m b/iOSMDMAgent/AppDelegate.m index db30851..fc8c3d5 100644 --- a/iOSMDMAgent/AppDelegate.m +++ b/iOSMDMAgent/AppDelegate.m @@ -6,6 +6,8 @@ #import "AppDelegate.h" #import "MDMUtils.h" #import "ConnectionUtils.h" +#import "ConnectionUtils.h" +#import "URLUtils.h" #define systemSoundID 1154 @@ -187,6 +189,19 @@ - (void) registerForPushToken { } } +- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { + if (status == kCLAuthorizationStatusAuthorized || status == kCLAuthorizationStatusDenied) { + NSLog(@"User responded to location"); + NSString *enrollURL = [URLUtils getEnrollmentURLFromPlist]; + NSString *serverURL = [URLUtils getEnrollmentURLFromPlist]; + if(enrollURL && ![@"" isEqualToString:enrollURL] && serverURL && ![@"" isEqualToString:serverURL]) { + [URLUtils saveServerURL:serverURL]; + [URLUtils saveEnrollmentURL:enrollURL]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[URLUtils getEnrollmentURL]]]; + } + } +} + - (void)initLocation { NSLog(@"Initializing location manager"); // __block UIBackgroundTaskIdentifier bgTask =0; diff --git a/iOSMDMAgent/Endpoints.plist b/iOSMDMAgent/Endpoints.plist index a1d8bcc..71bcb43 100644 --- a/iOSMDMAgent/Endpoints.plist +++ b/iOSMDMAgent/Endpoints.plist @@ -20,6 +20,8 @@ 8243 ENROLMENT_PORT 9443 + ENROLLMENT_URL + SERVER_URL https://gateway.api.cloudstaging.wso2.com diff --git a/iOSMDMAgent/LoginViewController.m b/iOSMDMAgent/LoginViewController.m index af86938..95f7658 100644 --- a/iOSMDMAgent/LoginViewController.m +++ b/iOSMDMAgent/LoginViewController.m @@ -61,8 +61,14 @@ - (void)enroll { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:INVALID_SERVER_URL message:INVALID_SERVER_URL_MESSAGE delegate:nil cancelButtonTitle:OK_BUTTON_TEXT otherButtonTitles:nil, nil]; [alertView show]; } else { + /* + If the user is allowed to type the server url, assuption is this is not a production environment, + Therefore, both Enrollment URL(manager node URL where the enrollment app is stored) and the gateway url are + taken as the same. Check didChangeAuthorizationStatus method in AppDeligate.m for production behaviour, + Where the URLs are hard coded. + */ [URLUtils saveServerURL:self.txtServer.text]; - + [URLUtils saveEnrollmentURL:self.txtServer.text]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[URLUtils getEnrollmentURL]]]; } } diff --git a/iOSMDMAgent/URLUtils.h b/iOSMDMAgent/URLUtils.h index ff2d9d0..a2c47bd 100644 --- a/iOSMDMAgent/URLUtils.h +++ b/iOSMDMAgent/URLUtils.h @@ -39,6 +39,7 @@ extern NSString *const OPERATION_URI; extern NSString *const OPERATION_ID_RESPOSNE; extern NSString *const STATUS; extern int OAUTH_FAIL_CODE; +extern NSString *const ENROLLMENT_URL; + (void)saveServerURL:(NSString *)serverURL; + (NSString *)getServerURL; @@ -50,6 +51,10 @@ extern int OAUTH_FAIL_CODE; + (NSString *)getUnenrollURL; + (NSString *)getRefreshTokenURL; + (NSString *)getOperationURL; ++ (void)saveEnrollmentURL:(NSString *)enrollURL; ++ (NSString *)getSavedEnrollmentURL; ++ (NSString *)getEnrollmentURLFromPlist; ++ (NSString *)getServerURLFromPlist; @end diff --git a/iOSMDMAgent/URLUtils.m b/iOSMDMAgent/URLUtils.m index 53d01e4..541c414 100644 --- a/iOSMDMAgent/URLUtils.m +++ b/iOSMDMAgent/URLUtils.m @@ -41,6 +41,7 @@ @implementation URLUtils NSString *const FORM_ENCODED = @"application/x-www-form-urlencoded"; NSString *const OPERATION_ID_RESPOSNE = @"operationId"; NSString *const STATUS = @"status"; +NSString *const ENROLLMENT_URL = @"ENROLLMENT_URL"; + (NSDictionary *)readEndpoints { @@ -61,10 +62,29 @@ + (NSString *)getAPIPort { return [[URLUtils readEndpoints] objectForKey:API_PORT]; } ++ (NSString *)getEnrollmentURLFromPlist { + return [[URLUtils readEndpoints] objectForKey:ENROLLMENT_URL]; +} + ++ (NSString *)getServerURLFromPlist { + return [[URLUtils readEndpoints] objectForKey:SERVER_URL]; +} + + (NSString *)getEnrolmentPort { return [[URLUtils readEndpoints] objectForKey:ENROLMENT_PORT]; } ++ (NSString *)getSavedEnrollmentURL { + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + return [userDefaults objectForKey:ENROLLMENT_URL]; +} + ++ (void)saveEnrollmentURL:(NSString *)enrollURL { + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:enrollURL forKey:ENROLLMENT_URL]; + [userDefaults synchronize]; +} + + (void)saveServerURL:(NSString *)serverURL { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setObject:serverURL forKey:SERVER_URL]; @@ -92,7 +112,7 @@ + (NSString *)getRefreshTokenURL{ } + (NSString *)getEnrollmentURL { - return [NSString stringWithFormat:@"%@:%@%@", [URLUtils getServerURL], [URLUtils getEnrolmentPort], [[URLUtils readEndpoints] objectForKey:ENROLLMENT_URI]]; + return [NSString stringWithFormat:@"%@:%@%@", [URLUtils getSavedEnrollmentURL], [URLUtils getEnrolmentPort], [[URLUtils readEndpoints] objectForKey:ENROLLMENT_URI]]; } @end