CCManageLocation.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // CCManageLocation.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 23/07/15.
  6. // Copyright (c) 2015 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCManageLocation.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @implementation CCManageLocation
  27. + (CCManageLocation *)shared
  28. {
  29. static CCManageLocation *shared;
  30. @synchronized(self)
  31. {
  32. if (!shared){
  33. shared = [CCManageLocation new];
  34. }
  35. return shared;
  36. }
  37. }
  38. - (void)startSignificantChangeUpdates
  39. {
  40. if (self.locationManager == nil) {
  41. self.locationManager = [[CLLocationManager alloc] init];
  42. self.locationManager.delegate = self;
  43. if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
  44. [self.locationManager requestAlwaysAuthorization];
  45. }
  46. [self.locationManager startMonitoringSignificantLocationChanges];
  47. }
  48. - (void)stopSignificantChangeUpdates
  49. {
  50. [self.locationManager stopMonitoringSignificantLocationChanges];
  51. }
  52. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
  53. {
  54. CLLocation* location = [locations lastObject];
  55. [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"update location manager: latitude %+.6f, longitude %+.6f", location.coordinate.latitude, location.coordinate.longitude]];
  56. [self.delegate changedLocation];
  57. }
  58. - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
  59. {
  60. [self.delegate statusAuthorizationLocationChanged];
  61. }
  62. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
  63. {
  64. [[NCCommunicationCommon shared] writeLog:[NSString stringWithFormat:@"Location manager didFailWithError: Unable to start location manager, %@", [error description]]];
  65. [self.delegate statusAuthorizationLocationChanged];
  66. }
  67. @end