2016-10-07 4 views
0

프레임 워크를 설정하고 프레임 워크를 설정하는 샘플 응용 프로그램 인 모든 비콘 감지 로직이있는 프레임 워크가 있습니다. 앱이 죽은 후에 지역 입력 및 종료 알림을 받고 싶습니다. 논리가 앱에있을 때 앱에서 알림을받을 수 있습니다. 그러나 논리가 프레임 워크에있을 때 알림을 얻지 못합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 모니터링을 중지 할 가비지 수집을 방지하기 위해프레임 워크의 백그라운드에서 비컨 감지

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) 
     } 
    } 
} 
+0

잘못 될 수있는 많은 것들이 많이 있습니다. 코드를 보지 않으면 어떤 대답도 야생 투기 일 따름입니다. 코드를 게시 할 수 있습니까? – davidgyoung

+0

'AppDelegate + BeaconMonitoring.swift'가 파일에 대한 링크로되어 있다고 확신 할 수는 없지만 아직 도달하지 못했습니다. 그럼에도 불구하고 StackOverflow의 표준 연습은 코드에 작은 * 발췌 부분 *을 게시하여 질문과 관련된 코드 부분을 표시하는 것입니다. – davidgyoung

+0

나는 업데이 트의 중간에 있었고, 마지막 코멘트는 실수로했습니다. 코드로 내 질문을 편집했습니다. – Vinuta

답변

1

locationManager 클래스 변수 수 있어야하고, 초기화하는 방법 내에서 이루어져야한다. 이와 같이 :

let locationManager: CLLocationManager! 

func registerForBeaconNotifications() { 
    self.locationManager = CLLocationManager() 
    ... 
+0

확인하고 업데이트하겠습니다! :) – Vinuta

+0

나는 이것을 시험해 보았습니다. 행운을 빌어 요. (당신이 생각할 수있는 그 밖의 것이 틀 렸습니까?) – Vinuta

+0

왜 작동하지 않는지 이유는 스 와이프를 사용하여 앱을 죽이고 그 경우 앱은 iBeacons 감지시 깨어나지 않습니다. 이 문제를 해결할 수있는 솔루션이 있습니까? – Vinuta