iOS 10で利用可能なユーザ通知フレームワークを使用しています。ユーザがUNLocationNotificationTriggerを使用して特定のジオロケーションを入力するたびに通知をトリガしようとしました。 Geoの位置をシミュレートしてシミュレータを使ってテストしようとしたとき、通知はトリガされませんが、ロケーションマネージャは更新されたジオロケーションを返します。これをシミュレータで実行するのではなく、実際のデバイスでテストする必要がありますか? Apple DocumentationによるとUNLocationNotificationTrigger-シミュレータで動作しません
7
A
答えて
2
:
アプリが位置情報サービスへのアクセスを要求しなければなりませんし、このクラスを使用することで使用中のアクセス権を持っている必要があります。ロケーションサービスの使用を許可するには、ロケーションベースのトリガーをスケジュールする前にCLLocationManagerのrequestWhenInUseAuthorization()メソッドを呼び出します。
私のエミュレータ/デバイスでは、「使用時」のアクセス許可では不十分な場合は、アクセス許可を「常に」に設定する必要があります。
したがって、
<key>NSLocationAlwaysUsageDescription</key>
<string>We use your location to warn you when there are adorable cats nearby</string>
はその後場所を活性化させるあなたのpinfo.listにこのキーを追加します。あなたが常に承認されていることを確認してから、トリガーを定義してください。たとえば、didChangeAuthorizationStatusでここで行っています。
class myClass : CLLocationManagerDelegate {
var locationManager: CLLocationManager()
func init() {
// Note: defining the location manager locally in this function won't work
// var locationManager: CLLocationManager()
// as it gets gargabe collected too early.
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) {(accepted, error) in
if !accepted {
logger.info("Notification access denied.")
}
}
// MARK CLLocationManagerDelegate:
func locationManager(manager: CLLocationManager,
didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
if status == .AuthorizedAlways {
let region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: 61.446812, longitude: 23.859914),
radius: 1000, identifier: "test")
logger.info("Notification will trigger at \(region)")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats:true)
let content = UNMutableNotificationContent()
content.title = "Oh Dear !"
content.body = "It's working!"
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "textNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
}
}
}
関連する問題
- 1. シミュレータで動作、iPhoneデバイスで動作しません
- 2. localizable.strings - シミュレータでは動作しますが、デバイスでは動作しません
- 3. NSUserdefaultsはシミュレータでは動作しますが、デバイスでは動作しません
- 4. NSUrlRequestはシミュレータでは動作しますが、iphoneでは動作しません
- 5. コアグラフィックエフェクト:シミュレータでは動作しますが、デバイスでは動作しません
- 6. CG Gradientはシミュレータで動作しますが、iPhoneでは動作しません
- 7. アプリはシミュレータで動作しますが、iPhoneでは動作しません
- 8. xcodeシミュレータでは動作しませんが、デバイス上で動作する
- 9. Phonegap/Cordova jQuery $ iOSシミュレータでは動作しません
- 10. NSLog InterfaceRotationはシミュレータで動作しませんか?
- 11. BackgoundオーディオがiOS10、iOS11シミュレータで動作しません
- 12. デバイスが動作しません。シミュレータは実行します
- 13. シミュレータは動作しますが、デバイスは動作しませんか?
- 14. Blackberry MapViewがデバイスで動作しません。シミュレータで作業中です
- 15. シミュレータを起動できません
- 16. iOS5シミュレータのstorekitサポート - キーボードが動作しませんか?
- 17. Xcode 8のシミュレータが動作しません
- 18. iOSシミュレータが突然動作を停止しました。「iOSシミュレータは起動できませんでした」他のメッセージはありません
- 19. マイボタンはiPhone(Retina 4インチ)シミュレータのタッチイベントを検出しませんが、iPhone(Retina 3.5インチ)シミュレータで動作します
- 20. iOSアプリはシミュレータでバックグラウンドモードで動作しますが、デバイスでは動作しません。
- 21. アプリ購入ではシミュレータでは動作しますが、iPhoneでは動作しません
- 22. JMDNSはシミュレータでは動作しますが、デバイス上では動作しません
- 23. Phonegapファイル転送iPhoneシミュレータでは動作しますが、デバイスでは動作しません
- 24. iOS 10.3音声テキストはシミュレータでは動作しますが、デバイスでは動作しません
- 25. UIVisualEffect blurViewは、シミュレータでは動作しますが、iPhoneでは動作しません。
- 26. レルムアプリケーションはシミュレータでは動作しますが、実際のデバイスでは動作しません
- 27. SQLiteはデバイス上で動作しますが、シミュレータでは動作しません。 sqlite3_prepare_v2が失敗する
- 28. xcode swift app、locationはシミュレータでは動作しますが、実際のデバイスでは動作しません
- 29. Alamofireのバックグラウンドはシミュレータでは動作しますが、デバイスでは動作しません
- 30. iOS 5.1デバイスでは動作しませんが、iOS 5.1シミュレータで動作します
実際のデバイスでも通知を受け取ることができません。 :/ – Rihards
シミュレータとデバイスの両方でUser Notification Frameworkを使用して、日付と時刻に基づいて通知をトリガすることができます。私はまだデバイス内の位置に基づく通知をチェックしています。 – Ashok
あなたはそれを修正することができましたか?そうでなければ私はあなたに手を差し伸べることができます。 –