프레임 워크를 설정하고 프레임 워크를 설정하는 샘플 응용 프로그램 인 모든 비콘 감지 로직이있는 프레임 워크가 있습니다. 앱이 죽은 후에 지역 입력 및 종료 알림을 받고 싶습니다. 논리가 앱에있을 때 앱에서 알림을받을 수 있습니다. 그러나 논리가 프레임 워크에있을 때 알림을 얻지 못합니다. 내가 도대체 뭘 잘못하고있는 겁니까? 모니터링을 중지 할 가비지 수집을 방지하기 위해프레임 워크의 백그라운드에서 비컨 감지
import UIKit
import CoreLocation
extension AppDelegate: CLLocationManagerDelegate {
func registerForBeaconNotifications() {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "83f9daec-4cae-54f1-b64e-846f12345d05")!, major: 10, minor: 10, identifier: "iPhone 6 Beacon")
locationManager.delegate = self
region.notifyOnEntry = true
region.notifyOnExit = true
region.notifyEntryStateOnDisplay = true
locationManager.startMonitoring(for: region)
locationManager.startRangingBeacons(in: region)
// Register for showing notification alerts
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: .alert, categories: nil))
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
let notification = UILocalNotification()
switch state {
case .inside:
notification.alertBody = "Entered region"
UIApplication.shared.presentLocalNotificationNow(notification)
case .outside:
notification.alertBody = "Exited region"
UIApplication.shared.presentLocalNotificationNow(notification)
default:
notification.alertBody = "Region unknown"
UIApplication.shared.presentLocalNotificationNow(notification)
}
}
}
잘못 될 수있는 많은 것들이 많이 있습니다. 코드를 보지 않으면 어떤 대답도 야생 투기 일 따름입니다. 코드를 게시 할 수 있습니까? – davidgyoung
'AppDelegate + BeaconMonitoring.swift'가 파일에 대한 링크로되어 있다고 확신 할 수는 없지만 아직 도달하지 못했습니다. 그럼에도 불구하고 StackOverflow의 표준 연습은 코드에 작은 * 발췌 부분 *을 게시하여 질문과 관련된 코드 부분을 표시하는 것입니다. – davidgyoung
나는 업데이 트의 중간에 있었고, 마지막 코멘트는 실수로했습니다. 코드로 내 질문을 편집했습니다. – Vinuta