Skip to content

Commit

Permalink
Merge pull request #11 from inoshperera/master
Browse files Browse the repository at this point in the history
Fix for iOS Agent does not support gateway implementation
  • Loading branch information
geethkokila authored Dec 5, 2017
2 parents 86ad020 + ccde697 commit 785f57b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
15 changes: 15 additions & 0 deletions iOSMDMAgent/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#import "AppDelegate.h"
#import "MDMUtils.h"
#import "ConnectionUtils.h"
#import "ConnectionUtils.h"
#import "URLUtils.h"

#define systemSoundID 1154

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions iOSMDMAgent/Endpoints.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>8243</string>
<key>ENROLMENT_PORT</key>
<string>9443</string>
<key>ENROLLMENT_URL</key>
<string></string>
<key>SERVER_URL</key>
<string>https://gateway.api.cloudstaging.wso2.com</string>
</dict>
Expand Down
8 changes: 7 additions & 1 deletion iOSMDMAgent/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]];
}
}
Expand Down
5 changes: 5 additions & 0 deletions iOSMDMAgent/URLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
22 changes: 21 additions & 1 deletion iOSMDMAgent/URLUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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];
Expand Down Expand Up @@ -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

0 comments on commit 785f57b

Please sign in to comment.