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

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

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

iOS 9は、アップル社のモバイルOSであるiOSシリーズのバージョン。特徴として検索機能の強化、Siriの機能改良、iPad向けマルチタスクなどがあります。マルチウィンドウ機能をサポートし、iPad向けマルチタスクもサポートされています。

Q&A

1回答

589閲覧

Geofence Region複数設定?

coredaa

総合スコア6

iOS 9

iOS 9は、アップル社のモバイルOSであるiOSシリーズのバージョン。特徴として検索機能の強化、Siriの機能改良、iPad向けマルチタスクなどがあります。マルチウィンドウ機能をサポートし、iPad向けマルチタスクもサポートされています。

0グッド

0クリップ

投稿2018/08/18 01:31

CLCircularRegionを複数設定したい

発生している問題・エラーメッセージ

なし

エラーメッセージ なし ### 該当のソースコード let geoFenceRegion:CLCircularRegion = CLCircularRegion(center: CLLocationCoordinate2DMake(33.654237, 130.693872),radius: 500.0,identifier: "TokyoTower") locationManager.startMonitoring(for: geoFenceRegion) ```ここに言語名を入力 ソースコード class ViewController: UIViewController, CLLocationManagerDelegate { var audioPlayerInstance : AVAudioPlayer! = nil @IBOutlet weak var myimage: UIImageView! let locationManager: CLLocationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() self.myimage.isHidden = true locationManager.delegate = self locationManager.requestAlwaysAuthorization() locationManager.startUpdatingLocation() locationManager.distanceFilter = 10 let geoFenceRegion:CLCircularRegion = CLCircularRegion(center: CLLocationCoordinate2DMake(33.654237, 130.693872),radius: 500.0,identifier: "TokyoTower") locationManager.startMonitoring(for: geoFenceRegion) let soundFilePath = Bundle.main.path(forResource: "new", ofType: "mp3")! let sound:URL = URL(fileURLWithPath: soundFilePath) // AVAudioPlayerのインスタンスを作成 do { audioPlayerInstance = try AVAudioPlayer(contentsOf: sound, fileTypeHint:nil) } catch { print("AVAudioPlayerインスタンス作成失敗") } // バッファに保持していつでも再生できるようにする audioPlayerInstance.prepareToPlay() audioPlayerInstance.volume = 2 UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound], completionHandler: {(success,error) in if error != nil{ print("失敗しました") } else{ print("成功しました") } }) } func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { print("設定したジオフェンスに入りました。") self.myimage.isHidden = false audioPlayerInstance.play() timedNotifications(inSeconds: 3) {(success) in if success { print("Successfully Notified") } } } func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) { print("設定したジオフェンスから出ました。") self.myimage.isHidden = true } func timedNotifications(inSeconds: TimeInterval, completion: @escaping (_ _Success: Bool) -> ()){ let trigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false) let content = UNMutableNotificationContent() content.title = "浦上亭お知らせ" content.subtitle = "本日のサービス" content.body = "高級手羽先30%OFFでの提供!19:00まで" let request = UNNotificationRequest(identifier: "customNotification", content: content,trigger: trigger) UNUserNotificationCenter.current().add(request) { (error) in if error != nil { completion(false) }else{ completion(true) } } } } ### 試したこと ジオフェンスを20箇所設定したい。

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

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

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

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

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

y_waiwai

2018/08/18 01:41

ソースコードは、<code>ボタンを押して、'''の枠の中に貼り付けてください
guest

回答1

0

class

1var audioPlayerInstance : AVAudioPlayer! = nil 2@IBOutlet weak var myimage: UIImageView! 3let locationManager: CLLocationManager = CLLocationManager() 4 5override func viewDidLoad() { 6super.viewDidLoad() 7self.myimage.isHidden = true 8locationManager.delegate = self 9locationManager.requestAlwaysAuthorization() 10locationManager.startUpdatingLocation() 11locationManager.distanceFilter = 10 12 13let geoFenceRegion:CLCircularRegion = CLCircularRegion(center: CLLocationCoordinate2DMake(33.654237, 130.693872),radius: 500.0,identifier: "TokyoTower") 14locationManager.startMonitoring(for: geoFenceRegion) 15 16let soundFilePath = Bundle.main.path(forResource: "new", ofType: "mp3")! 17let sound:URL = URL(fileURLWithPath: soundFilePath) 18// AVAudioPlayerのインスタンスを作成 19do { 20audioPlayerInstance = try AVAudioPlayer(contentsOf: sound, fileTypeHint:nil) 21} catch { 22print("AVAudioPlayerインスタンス作成失敗") 23} 24// バッファに保持していつでも再生できるようにする 25audioPlayerInstance.prepareToPlay() 26audioPlayerInstance.volume = 2 27 28UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound], completionHandler: {(success,error) in 29if error != nil{ 30print("失敗しました") 31} 32else{ 33print("成功しました") 34} 35}) 36} 37 38func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { 39print("設定したジオフェンスに入りました。") 40self.myimage.isHidden = false 41audioPlayerInstance.play() 42 43timedNotifications(inSeconds: 3) {(success) in 44if success { 45print("Successfully Notified") 46} 47} 48 49} 50 51func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) { 52print("設定したジオフェンスから出ました。") 53self.myimage.isHidden = true 54 55} 56 57func timedNotifications(inSeconds: TimeInterval, completion: @escaping (_ _Success: Bool) -> ()){ 58let trigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false) 59let content = UNMutableNotificationContent() 60 61content.title = "浦上亭お知らせ" 62content.subtitle = "本日のサービス" 63content.body = "高級手羽先30%OFFでの提供!19:00まで" 64 65let request = UNNotificationRequest(identifier: "customNotification", content: content,trigger: trigger) 66UNUserNotificationCenter.current().add(request) { (error) in 67if error != nil { 68completion(false) 69 70}else{ 71completion(true) 72 73} 74} 75} 76} 77 78 79コード

投稿2018/08/18 01:52

coredaa

総合スコア6

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問