スクリーンオフの状態でlocal notificationを表示するとき、バイブレーションを出したいです。
しかし、表示はされるのですが、音もなくバイブレーションも出ません。なぜでしょうか?
以下のコードはビーコンの通信が切れた時にnotificationを発生するコードです。
swift
1 2import UIKit 3import CoreLocation 4import UserNotifications 5import NotificationCenter 6import AudioToolbox 7 8class PasstyListViewController: SlideMenuController, UICollectionViewDelegate, UICollectionViewDataSource, CLLocationManagerDelegate, UNUserNotificationCenterDelegate { 9. 10. 11. 12 13func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) { 14 print("didExitRegion: iBeacon lost"); 15 let beacon = region as! CLBeaconRegion 16 if beacon.major != nil && beacon.minor != nil { 17 if let customCell: CustomCell = self.view.viewWithTag(beacon.major!.intValue * 1000 + beacon.minor!.intValue) as? CustomCell{ 18 AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) 19 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 20 customCell.resetProximity() 21 customCell.Result.text = "近くに見つかりません" 22 let content = UNMutableNotificationContent() 23 content.title = "hogehogeは手元にありますか?" 24 content.body = "hogehogeを見失いました" 25 let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: false) 26 let request = UNNotificationRequest.init(identifier: "CloseScreenAlertNotification", content: content, trigger: trigger) 27 let center = UNUserNotificationCenter.current() 28 center.add(request) 29 center.delegate = self 30 } 31 } 32 manager.stopRangingBeacons(in: beacon) 33 } 34}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。