2017-11-30 6 views
0

私はの新機能です。ビーコンプログラミング.iアプリを閉じているときにを見積もります。ビーコンを検出します。ビーコンが検出されたら、特定の通知を発します。どのように私はそれを行うことができますか? 私に提案をお願いします。私は次のコードを実行しました。しかし、私は通知を得ることができませんアプリがアイオスで殺されたときに推定ビーコンを検出するにはどうすればよいですか?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
beaconManager.delegate = self 
     beaconManager.startMonitoring(for: region) 
     beaconManager.startRangingBeacons(in: region) 
} 

func beaconManager(_ manager: Any, didEnter region: CLBeaconRegion) { 
     NSLog("beaconManager : didEnter Called") 
     let content = UNMutableNotificationContent() 
     content.title = "Beacon Detected" 
     content.body = "Enter region" 
     content.sound = UNNotificationSound.default() 

     let trigger = UNLocationNotificationTrigger(region:region, repeats:false) 
     let request = UNNotificationRequest(identifier: "Enter region", content: content, trigger: trigger) 
     center.add(request) { (error) in 
      if let error = error { 
       print(error.localizedDescription) 
      } 
     } 
    } 
func beaconManager(_ manager: Any, didExitRegion region: CLBeaconRegion) { 
      NSLog("beaconManager : didExitRegion Called") 
      let content = UNMutableNotificationContent() 
      content.title = "Beacon Detected" 
      content.body = "Exit region" 
      content.sound = UNNotificationSound.default() 

      let trigger = UNLocationNotificationTrigger(region:region, repeats:false) 
      let request = UNNotificationRequest(identifier: "Enter region", content: content, trigger: trigger) 
      center.add(request) { (error) in 
       if let error = error { 
        print(error.localizedDescription) 
       } 
      } 
     } 

答えて

0

アプリケーションの代理人は、推定代理人のメソッドの下で希望のコードを書いてください。サンプルコードは、次のようになります。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { 
if launchOptions["UIApplicationLaunchOptionsLocationKey"] != nil { 
    beaconManager = ESTBeaconManager() 
    beaconManager.delegate = self 
    // don't forget the NSLocationAlwaysUsageDescription in your Info.plist 
    beaconManager.requestAlwaysAuthorization() 
    beaconManager.startMonitoring(for: ESTBeaconRegion(proximityUUID: ESTIMOTE_PROXIMITY_UUID, identifier: "AppRegion")) 
    } 
    return true 
} 

func beaconManager(_ manager: ESTBeaconManager, didEnter region: ESTBeaconRegion) { 
    let notification = UILocalNotification() 
    notification.alertBody = "Enter region" 
    notification.soundName = UILocalNotificationDefaultSoundName as? String 
    UIApplication.shared.presentLocalNotificationNow(notification) 
} 
func beaconManager(_ manager: ESTBeaconManager, didExitRegion region: ESTBeaconRegion) { 
    let notification = UILocalNotification() 
    notification.alertBody = "Exit region" 
    notification.soundName = UILocalNotificationDefaultSoundName as? String 
    UIApplication.shared.presentLocalNotificationNow(notification) 
} 

これは古いコードであり、変更がほとんどない可能性があります。詳細については、推定コミュニティのスレッドに従ってください。あなたはこのスレッドであなたの問題を見つけることができますhttps://community.estimote.com/hc/en-us/articles/203253193-Pushing-notifications-from-iBeacon-when-the-app-is-in-the-background-or-killed

+0

私はそれを試みましたが、何も起こりません。 –

+0

あなたの試したコードを表示してください。 – jegadeesh

+0

あなたの質問にコードを書いてください。コメントでそれらを読むのは難しい。 – jegadeesh

関連する問題