【问题标题】:Core location alerts核心位置警报
【发布时间】:2012-11-30 02:58:12
【问题描述】:

我在 O'Reilly 教程中看到以下警报:

  1. http://answers.oreilly.com/index.php?app=core&module=attach&section=attach&attach_rel_module=post&attach_id=125
  2. http://answers.oreilly.com/uploads/monthly_10_2009/post-48-125435525931_thumb.jpg

我不明白如何触发这些警报。请问你能通知我吗?使用ios6的应用

【问题讨论】:

    标签: iphone ios alert core-location


    【解决方案1】:

    这是访问您当前位置时的警报,当您使用CLLocationManager访问用户当前位置时,它会自动询问

    -(void)getLocation
    {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLLocationAccuracyHundredMeters;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    
        NSLog(@"eee%f",locationManager.location.coordinate.latitude);
        // Start updating location changes.
        [locationManager startUpdatingLocation];
    }
    
    
    - (void)startUpdatingCurrentLocation
    {
        //NSLog(@"STARTUPDATELOCATION");
        // if location services are restricted do nothing
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
            [CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
        {
            return;
        }
    
        // if locationManager does not currently exist, create it
        if (!locationManager)
        {
            locationManager = [[CLLocationManager alloc] init];
            [locationManager setDelegate:self];
            locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
    
    
        }
    
        [locationManager startUpdatingLocation];
    
        // [self showCurrentLocationSpinner:YES];
    }
    

    阅读CLLocationManager Class Reference了解更多信息

    【讨论】:

      【解决方案2】:

      好吧,这该死的简单。它被称为UIAlertView,用于发送通知非常常见。它们应该用于通知用户一些事情,而不是太多的交互。

      编码明智,这里是一些基本的设置文本:

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alert Body" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
      

      显示警报:

      [alert show];
      

      如果您想要其他按钮标题,您需要将delegate 设置为self,并在您的.h 文件中与UIAlertViewDelegate 保持一致。 Here Is The Reference To The Delegate 并且您基本上想要实现 clickedButtonAtIndex: 方法并使用索引来找出用户按下了哪个按钮并执行操作。

      Do not misuse alert views.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        • 2011-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-29
        相关资源
        最近更新 更多