質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1130閲覧

Local Notificationが表示されるときのバイブレーションについて

yusukechief

総合スコア16

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2018/03/21 07:56

スクリーンオフの状態で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}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

content.sound = UNNotificationSound.default()
これを入れないといけなかったみたいです。

投稿2018/03/21 08:25

yusukechief

総合スコア16

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問