2016-10-07 4 views
0

私はすべてのビーコン検出ロジックと、フレームワークを設定して崩壊させるサンプルアプリケーションを持ったフレームワークを持っています。私はアプリが殺された後、領域の入力と終了の通知を取得したい。ロジックがアプリにあるときにアプリから通知を受け取ることができます。しかし、ロジックがフレームワークにあるとき、私は通知を受けません。私は間違って何をしていますか?監視を停止しますガベージコレクション、locationManagerはクラス変数であることが必要であり、初期化メソッドの内部で行われなければならないことを防止するためにフレームワークのバックグラウンドでのビーコン検出

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

。このように:

let locationManager: CLLocationManager! 

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

私に確認して更新させてください! :) – Vinuta

+0

私はこれを試しました、運はありません:(あなたが考えることができる何かが間違っていますか?) – Vinuta

+0

なぜ私はアプリを殺すためにスワイプを使用していましたが、その場合アプリはiBeaconsを検出しても目が覚めません。これを処理するソリューションはありますか? – Vinuta

関連する問題