zoukankan      html  css  js  c++  java
  • 后台定位

    #import "LocationsAppDelegate.h"
    #import "RootViewController.h"
     
    @implementation LocationsAppDelegate
    @synthesize window;
    @synthesize navigationController;
     
    -(void)initLocationManager {                         #1
         if (locationManager == nil) {
              locationManager = [[CLLocationManager alloc] init];
              locationManager.delegate = self;
              [locationManager startMonitoringSignificantLocationChanges];
         }
    }
    - (void)saveCurrentData:(NSString *)newData {               #2
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSMutableArray *savedData = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"kLocationData"]];
         [savedData addObject:newData];
         [defaults setObject:savedData forKey:@"kLocationData"];
         [savedData release];
    }
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions      
    { 
      if (![CLLocationManager significantLocationChangeMonitoringAvailable]) #3 
    {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Your device won't support the significant location change." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
              [alert show];
              [alert release];
              return YES;                                   #3
         }                                             #3
         [self initLocationManager];
        [self.window addSubview:navigationController.view];
        [self.window makeKeyAndVisible];
        return YES;
    }
     
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {                                        #4
         NSString *locationData = [NSString stringWithFormat:@"%.6f, %.6f",newLocation.coordinate.latitude, newLocation.coordinate.longitude];
         [self saveCurrentData:locationData];
    }                                                  #4
     
    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {                         #5
         NSString *errorData = [NSString stringWithFormat:@"%@",[error localizedDescription]];
         NSLog(@"%@", errorData);                              #5
    }
    - (void)dealloc {
         [[NSNotificationCenter defaultCenter] removeObserver:self];
    [locationManager release];
        [navigationControllerrelease];
        [window release];
        [super dealloc];
    }
    
    @end
  • 相关阅读:
    bzoj2588 Count on a tree
    poco对象生成的几种方式根据你使用不同的ui决定
    airtest本地连接和远程连接
    python音频文件中pcm格式提取
    python提取视频中的音频
    如何理解快速排序的时间复杂度是O(nlogn)
    剑指 Offer 45. 把数组排成最小的数
    剑指 Offer 44. 数字序列中某一位的数字
    剑指 Offer 43. 1~n 整数中 1 出现的次数
    剑指 Offer 41. 数据流中的中位数
  • 原文地址:https://www.cnblogs.com/chenfulai/p/2514409.html
Copyright © 2011-2022 走看看