Skip to content

Commit

Permalink
Merge pull request #7 from milanperera/master
Browse files Browse the repository at this point in the history
Fixed location updating issue and Return key issue
  • Loading branch information
madhawap authored Jul 24, 2017
2 parents 08877b2 + dd04ac6 commit c86f7be
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 38 deletions.
18 changes: 9 additions & 9 deletions iOSMDMAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
14BD72271A83479800D43DE5 = {
CreatedOnToolsVersion = 6.1.1;
DevelopmentTeam = KED4SHKL8S;
ProvisioningStyle = Manual;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
Expand Down Expand Up @@ -472,15 +472,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = iOSMDMAgent/iOSMDMAgent.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution: WSO2 Inc";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
DEVELOPMENT_TEAM = KED4SHKL8S;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = iOSMDMAgent/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.wso2.carbon.emm.ios.agent;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "008bd780-edd6-4f7e-b5b4-6861209b4617";
PROVISIONING_PROFILE_SPECIFIER = "WSO2 EMM iOS Enterprise provision profile";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -491,15 +491,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = iOSMDMAgent/iOSMDMAgent.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution: WSO2 Inc";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
DEVELOPMENT_TEAM = KED4SHKL8S;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = iOSMDMAgent/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.wso2.carbon.emm.ios.agent;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "008bd780-edd6-4f7e-b5b4-6861209b4617";
PROVISIONING_PROFILE_SPECIFIER = "WSO2 EMM iOS Enterprise provision profile";
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
36 changes: 25 additions & 11 deletions iOSMDMAgent/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

_connectionUtils = [[ConnectionUtils alloc] init];
_connectionUtils.delegate = self;

self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.distanceFilter = LOCATION_DISTANCE_FILTER;
_locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

// Set a movement threshold for new events.
self.locationManager.distanceFilter = 10; // meters

// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
Expand Down Expand Up @@ -186,11 +189,23 @@ - (void) registerForPushToken {

- (void)initLocation {
NSLog(@"Initializing location manager");
__block UIBackgroundTaskIdentifier bgTask =0;
UIApplication *application = [UIApplication sharedApplication];
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
[self.locationManager startUpdatingLocation];
}];
// __block UIBackgroundTaskIdentifier bgTask =0;
// UIApplication *application = [UIApplication sharedApplication];
// bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// [self.locationManager startUpdatingLocation];
// }];
if (nil == self.locationManager) {
self.locationManager = [[CLLocationManager alloc] init];
}

self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

// Set a movement threshold for new events.
self.locationManager.distanceFilter = 10; // meters

[self.locationManager startUpdatingLocation];

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
Expand All @@ -201,15 +216,14 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {

NSLog(@"Sending location updates to the server");

NSString *udid = [MDMUtils getDeviceUDID];
CLLocation *location = [locations lastObject];

if (location && udid) {
[_connectionUtils sendLocationToServer:udid latitiude:location.coordinate.latitude longitude:location.coordinate.longitude];
}

}
[self.locationManager stopUpdatingLocation];

}

- (void)triggerAlert {
Expand Down
2 changes: 1 addition & 1 deletion iOSMDMAgent/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<rect key="frame" x="20" y="297.33333333333331" width="374" height="17"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="URL" returnKeyType="go"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Add server address and press 'Enroll Device' to connect your device to WSO2 IoT Server" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u7v-4T-Vc8">
<rect key="frame" x="20" y="251.33333333333331" width="374" height="20.999999999999943"/>
Expand Down
11 changes: 5 additions & 6 deletions iOSMDMAgent/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
<array>
<dict>
<key>CFBundleURLName</key>
<string>org.wso2.mdm.agent</string>
<string>wso2.carbon.emm.ios.agent</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wso2agent</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>RC1</string>
<string>RC2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand All @@ -39,7 +39,7 @@
<true/>
</dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>Device Cloud server will require to pull location updates</string>
<string>WSO2 IoT server will require to pull location updates</string>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
Expand All @@ -54,6 +54,8 @@
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>location-services</string>
<string>gps</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
Expand All @@ -62,9 +64,6 @@
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions iOSMDMAgent/LoginViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
@property (strong, nonatomic) IBOutlet UITextField *txtServer;

- (IBAction)clickOnRegister:(id)sender;
- (void)enroll;

@end
28 changes: 17 additions & 11 deletions iOSMDMAgent/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface LoginViewController ()
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.txtServer.delegate = self;
// Do any additional setup after loading the view.
}

Expand All @@ -35,9 +36,22 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
*/

- (IBAction)clickOnRegister:(id)sender {

//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[URLUtils getEnrollmentURL]]];

[self enroll];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.txtServer) {
[textField resignFirstResponder];
NSLog(@"Pressed GO");
[self enroll];
return NO;
}
NSLog(@"YES");
return YES;
}

- (void)enroll {
NSURL *serverURL = [NSURL URLWithString:self.txtServer.text];

if (!self.txtServer || [@"" isEqualToString:self.txtServer.text]) {
Expand All @@ -51,14 +65,6 @@ - (IBAction)clickOnRegister:(id)sender {

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[URLUtils getEnrollmentURL]]];
}

}

-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
[textField resignFirstResponder];

return YES;
}

@end

0 comments on commit c86f7be

Please sign in to comment.