当我重新启动设备时,我的IOS应用程序没有任何区域更新吗? [英] MY IOS App is not getting any region updates when ever I restart my device any ideas?

查看:82
本文介绍了当我重新启动设备时,我的IOS应用程序没有任何区域更新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在前台和后台运行时,即使在退出应用程序时,也可以在后台运行。.但是当我重新启动手机时,它并没有唤醒。.

My app is working fine for beacon monitoring when running in foreground and background even when I quit app it's launching the app in background .. But when I restart the phone it's not waking up..

//我也在使用后台模式进行定位

// I am using background modes for location also

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //do i have to do anything here

    return true
}

///当应用程序命中后台波纹管方法将触发并且我开始区域监视时

//when ever app hit background bellow method will trigger and there i am starting region monitoring

func applicationDidEnterBackground(_ application: UIApplication) {


    do {
        try DLGatewayInterface.getInstance().enableBackgroundWakeups()
        try DLGatewayInterface.getInstance().startBackgroundScan(start: true)
    } catch let error {
        print(error)
    }


}

//这将在应用程序启动区域监视时触发,我在这里设置委托人

// This will trigger when ever app starts region monitoring here i am setting up delegate

var gatewayBridgeDelegate: DLGatewayBridgeDelegate?
private var locationManager:CLLocationManager
private var Region:CLBeaconRegion
var savedDevices = UserDefaults.standard
var major = ""
var minor = ""

override init() {


    locationManager = CLLocationManager()


    super.init()

    locationManager.delegate = self

    // required as "ALWAYS" for iBeacon
    locationManager.requestAlwaysAuthorization()

}

//这将在每次应用到达背景时触发

// this will trigger every time when app hits background

public func startRegionMonitoring()
{

    if let beaconName = UserDefaults.standard.value(forKey: "beaconDeviceRegion") as? String{
        print(beaconName)

        self.decimalToHexForMajorMinor(value: beaconName)

        danlawRegion = CLBeaconRegion(
            proximityUUID: BeaconServiceId,
            major: CLBeaconMajorValue(DLUtils.beaconMajor),
            minor: CLBeaconMinorValue(DLUtils.beaconMinor),
            identifier: "Danlaw")
                // reset the regions...just in case
          stopRegionMonitoring()
        // only add it if you need to
        if(!locationManager.monitoredRegions.contains(Region)) {
            locationManager.startMonitoring(for: Region)
        }
    }

}


public func stopRegionMonitoring(){
    danLogDebug()
    locationManager.stopMonitoring(for: danlawRegion)
    resetRegions() // clear all regions...
}




 extension DLLocationManager: CLLocationManagerDelegate {
public func locationManager(_ manager: CLLocationManager, 
didChangeAuthorization status: CLAuthorizationStatus) {
    if status == .authorizedAlways || status == .authorizedWhenInUse {

    }
}

public func locationManager(_ manager: CLLocationManager, 
didFailWithError error: Error) {
    danLogWarn(error.localizedDescription)
}

public func locationManager(_ manager: CLLocationManager, 
didUpdateLocations locations: [CLLocation]) {

}

public func locationManager(_ manager: CLLocationManager, 
didEnterRegion region: CLRegion) {
    // in this bellow method i am calling scanning again
    onRegionEnter(region: region.identifier)

}

public func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {

    onRegionExit(region: region.identifier)

}

public func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) {

}
public func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {


    onRegionDetermineState(region: region.identifier, state: state.rawValue)
}
public func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion) {

    onRegionMonitorStart(region: region.identifier)
}

}

推荐答案

您必须设置信标监视并在<$ c $中设置CoreLocation委托c> didFinishLaunching 。否则,您将不会获得自动启动行为。

You must set up beacon monitoring and set the CoreLocation delegate in didFinishLaunching. If you do not, you will not get auto launching behavior.

var locationManager: CLLocationManager?  

func application(_ application: UIApplication,  didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  locationManager = CLLocationManager()
  locationManager?.delegate = self
  let region = CLBeaconRegion(proximityUUID: Uuid, identifier: "my_region")
  locationManager?.startMonitoring(for: region)
}

这篇关于当我重新启动设备时,我的IOS应用程序没有任何区域更新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆