2015-09-16 3 views
1

Я создаю iOS Framework, и я хочу использовать Core Location для взаимодействия с Beacons. По причинам тестирования я пытаюсь получить местоположение пользователя.Расположение ядра в iOS Framework

Это класс, который я создал в рамках.

import Foundation 
import CoreLocation 

public class BeaconManager:NSObject,CLLocationManagerDelegate{ 

    var locationManager:CLLocationManager = CLLocationManager() 

    public override init() { 
     super.init() 
     locationManager.requestAlwaysAuthorization() 
     locationManager.delegate = self 
     locationManager.startUpdatingLocation() 
    } 

    public func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 
     if let location = locations.first as? CLLocation { 
      println(location) 
     } 
    } 
} 

И я зову его из тестового приложения, которое имеет структуру, как этот

import UIKit 
import OtravitaSDK 
import CoreLocation 

class ViewController: UIViewController { 

     var bm = BeaconManager() 

    override func viewDidLoad() { 
     super.viewDidLoad() 


     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


} 

Но не работает, не печатает местоположение. Я поставил NSLocationAlwaysUsageDescription как в info.plist фреймворки и info.plist в приложениях

+1

Вы получаете запрос о разрешении доступа местоположение? – Paulw11

+0

Нет, я не. Благодарю за ваш ответ. –

ответ

1

Вы можете добавить свой Decription в NSLocationAlwaysUsageDescription & NSLocationWhenInUseUsageDescription в PLIST

Этот код введен в AppDelegate файл

 var locationManager:CLLocationManager? 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

     //You can give this permission for fetch current location 
     var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound; 
     var setting = UIUserNotificationSettings(forTypes: type, categories: nil); 
     UIApplication.sharedApplication().registerUserNotificationSettings(setting); 
     UIApplication.sharedApplication().registerForRemoteNotifications(); 

     locationManager = CLLocationManager() 
     locationManager?.requestAlwaysAuthorization() 
     locationManager?.delegate = self 
     locationManager?.startUpdatingLocation() 

     // Override point for customization after application launch. 
     return true 
    } 

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 
     if let location = locations.first as? CLLocation { 
      println(location) 
     } 
    } 
0

Что вам нужно сделать, как ИО 8, настроить Info.plist file обслуживать 2 вида поведения местонахождения. Вам необходимо предоставить сообщение по умолчанию, которое появляется со всплывающим меню по умолчанию, и попросить пользователя дать согласие на использование своего местоположения.

NSLocationWhenInUseUsageDescription и NSLocationAlwaysUsageDescription

См this article для полного пошагового и another SO post который обсуждает эту тему. Надеюсь это поможет!

Смежные вопросы