我試圖在用戶接近站點時獲取一些公交車到達時間,我已經過測試以確保通過發送基本本地通知來正確觸發區域,並且我還測試了我的網絡服務電話,以確保它正常工作。基於動態位置的本地通知Swift iOS
但是,我很難獲取信息,然後發送通知。
這裏是我的代碼:
var bgTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier()
bgTask = UIApplication.shared().beginBackgroundTask {
self.webService?.getStopEstimates(routeStopIds: stopRouteIdSet, routeNameDict: routeNameDict, completion: { (result) in
if result == "error" {
return
}
let notification = UILocalNotification()
notification.fireDate = Date(timeIntervalSinceNow: 1)
notification.alertTitle = region.identifier + " Stop Details"
notification.alertBody = result
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.shared().scheduleLocalNotification(notification)
})
UIApplication.shared().endBackgroundTask(bgTask)
}
任何一個明白爲什麼它可能尚未發送?我已啓用後臺提取和位置服務。這是didEnterRegion
既然你'使用Swift 3知道有一個新的UserNotifications框架。 – tktsubota
難道你確實忘記了在基金申請中註冊通知(_申請:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?)。註冊碼:let notificationSettings = UIUserNotificationSettings(類型:.alert,類別:無) application.registerUserNotificationSettings(notificationSettings) – Ramis
您如何測試?在Xcode中?添加一些日誌記錄來檢查請求是否被髮送/接收。任何錯誤? – Wain