{"id":6105,"date":"2022-06-25T18:39:53","date_gmt":"2022-06-25T10:39:53","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6105"},"modified":"2022-06-25T18:39:53","modified_gmt":"2022-06-25T10:39:53","slug":"swift4%e9%80%9a%e7%9f%a5%e3%81%ae%e5%87%ba%e3%81%97%e6%96%b9","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6105","title":{"rendered":"[Swift4]\u901a\u77e5\u306e\u51fa\u3057\u65b9"},"content":{"rendered":"\n<p>\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u901a\u77e5\u3092\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u81ea\u5206\u306e\u8a00\u8449\u3067\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002(Swift4)<\/p>\n\n\n\n<p><strong>1.\u30a4\u30f3\u30dd\u30fc\u30c8<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- wp:paragraph -->\n&lt;p>&lt;\/p>\n&lt;!-- \/wp:paragraph --><\/pre>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#2%E9%80%9A%E7%9F%A5%E8%A8%B1%E5%8F%AF%E3%83%80%E3%82%A4%E3%82%A2%E3%83%AD%E3%82%B0%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B\"><\/a>2.\u901a\u77e5\u8a31\u53ef\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u8868\u793a\u3059\u308b<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u901a\u77e5\u8a31\u53ef\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u8868\u793a\n        let center = UNUserNotificationCenter.current()\n        center.requestAuthorization(options: [.alert, .sound, .badge]) {\n            (granted, error) in\n            \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n        }\n<\/pre>\n\n\n\n<p>\u901a\u77e5\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u51fa\u3057\u305f\u3044\u3068\u3053\u308d\u306b\u8a18\u5165\u3059\u308b\u3002\u306a\u3093\u306e\u305f\u3081\u306b\u901a\u77e5\u3092\u8a31\u53ef\u3059\u308b\u306e\u304b\u4e8b\u524d\u306b\u4f55\u3089\u304b\u306e\u5f62\u3067\u793a\u3057\u3066\u304a\u304f\u3068\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u6761\u4ef6\u53cd\u5c04\u3067\u901a\u77e5\u30aa\u30d5\u306b\u3059\u308b\u3053\u3068\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u3066\u3044\u3044\u3002<br>\u3068\u308a\u3042\u3048\u305a\u6700\u521d\u306e\u3046\u3061\u306fViewDidLoad\u306b\u5165\u308c\u3066\u304a\u3051\u3070\u554f\u984c\u306a\u3044\u304b\u306a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#3%E9%80%9A%E7%9F%A5%E3%81%AE%E5%86%85%E5%AE%B9%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B\"><\/a><\/h2>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#3%E9%80%9A%E7%9F%A5%E3%81%AE%E5%86%85%E5%AE%B9%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B\"><\/a>3.\u901a\u77e5\u306e\u5185\u5bb9\u3092\u8a2d\u5b9a\u3059\u308b<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        \/\/ \u901a\u77e5\u5185\u5bb9\u306e\u8a2d\u5b9a\n        let content = UNMutableNotificationContent()\n        \/\/ \u901a\u77e5\u306e\u30bf\u30a4\u30c8\u30eb\u3092\u8a2d\u5b9a\n        content.title = NSString.localizedUserNotificationString(forKey: \"Title\", arguments: nil)\n        \/\/ \u901a\u77e5\u306e\u672c\u6587\u3092\u8a2d\u5b9a\n        content.body = NSString.localizedUserNotificationString(forKey: \"Message\", arguments: nil)\n        \/\/ \u901a\u77e5\u306e\u97f3\u697d\u3092\u8a2d\u5b9a\n        content.sound = UNNotificationSound.default()\n\n        \/\/\u203b\u7528\u610f\u3057\u305f\u97f3\u697d\u3092\u4f7f\u3046\u5834\u5408\u306f\u3053\u3093\u306a\u611f\u3058\n        \/\/ content.sound = UNNotificationSound(named:\"xxxx.mp3\")\n<\/pre>\n\n\n\n<p>UNMutableNotificationContent\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u7528\u3057\u3066\u901a\u77e5\u306e\u5185\u5bb9\u3092\u8a2d\u5b9a\u3059\u308b\u3002<br>\u30b3\u30d4\u30fc\u3057\u3066\u9069\u5f53\u306b\u5909\u3048\u308c\u3070\u3044\u3044\u611f\u3058\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#4%E3%83%88%E3%83%AA%E3%82%AC%E3%83%BC%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B\"><\/a>4.\u30c8\u30ea\u30ac\u30fc\u3092\u8a2d\u5b9a\u3059\u308b<\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#4-1%E6%97%A5%E6%99%82%E6%8C%87%E5%AE%9A%E3%81%A7%E3%83%88%E3%83%AA%E3%82%AC%E3%83%BC%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88\"><\/a>4-1.\u65e5\u6642\u6307\u5b9a\u3067\u30c8\u30ea\u30ac\u30fc\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        \/\/20\u664215\u520630\u79d2\u306b\u901a\u77e5\u3059\u308b\u5834\u5408\n        formatter.dateFormat = 20\n        fireDate.hour = 20\n        fireDate.minute = 15\n        fireDate.second = 30\n        let trigger = UNCalendarNotificationTrigger(dateMatching: fireDate, repeats: false)\n<\/pre>\n\n\n\n<p>\u306a\u304a\u3001\u73fe\u5728\u6642\u523b\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u3092\u5229\u7528\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        let formatter = DateFormatter()\n        formatter.dateFormat = \"HH\"\n        fireDate.hour = Int(formatter.string(from: Date()))!\n        formatter.dateFormat = \"mm\"\n        fireDate.minute = Int(formatter.string(from: Date()))!\n        formatter.dateFormat = \"ss\"\n        fireDate.second = Int(formatter.string(from: Date()))!<\/pre>\n\n\n\n<p>\u73fe\u5728\u6642\u9593\u304b\u30895\u6642\u9593\u5f8c\u306a\u3069\u306e\u3088\u3046\u306b\u3057\u305f\u3044\u969b\u306f\u3001\u4e0a\u8a18\u8a72\u5f53\u306e\u7b87\u6240\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u63db\u3048\u308b\u3053\u3068\u3067\u7c21\u5358\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br><code>fireDate.hour = Int(formatter.string(from: Date()))! + 5<\/code><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#4-2%E7%B5%8C%E9%81%8E%E6%99%82%E9%96%93%E3%81%A7%E3%83%88%E3%83%AA%E3%82%AC%E3%83%BC%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88\"><\/a>4-2.\u7d4c\u904e\u6642\u9593\u3067\u30c8\u30ea\u30ac\u30fc\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        \/\/5\u79d2\u5f8c\u306b\u901a\u77e5\u3059\u308b\u5834\u5408\n        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: true)\n<\/pre>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#5%E9%80%9A%E7%9F%A5%E3%81%AE%E3%83%AA%E3%82%AF%E3%82%A8%E3%82%B9%E3%83%88%E3%82%92%E8%A8%AD%E5%AE%9A\"><\/a>5.\u901a\u77e5\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u8a2d\u5b9a<\/strong><\/p>\n\n\n\n<p>\u901a\u77e5\u767b\u9332\u7528\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u3002<br>identifier\u306f\u73fe\u72b6\u4f7f\u3044\u9053\u304c\u308f\u304b\u3063\u3066\u3044\u306a\u3044\u304c\u3001\u9069\u5f53\u306b\u8a18\u8f09\u3057\u3068\u3051\u3070\u826f\u3044\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">let request = UNNotificationRequest(identifier: \"Identifier\", content: content, trigger: trigger)<\/pre>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#6%E9%80%9A%E7%9F%A5%E3%82%92%E7%99%BB%E9%8C%B2\"><\/a>6.\u901a\u77e5\u3092\u767b\u9332<\/strong><\/p>\n\n\n\n<p>\u901a\u77e5\u3059\u308b\u3082\u306e\u3092\u3053\u3046\u3084\u3063\u3066\u767b\u9332\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u307f\u305f\u3044\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        \/\/ \u901a\u77e5\u3092\u767b\u9332\n        center.add(request) { (error : Error?) in\n            if error != nil {\n                \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n            }\n        }\n<\/pre>\n\n\n\n<p><strong><a href=\"https:\/\/qiita.com\/tojo\/items\/3189867605d3b1c5816e#7%E5%AE%8C%E6%88%90%E3%81%97%E3%81%9F%E3%82%BD%E3%83%BC%E3%82%B9\"><\/a>7.\u5b8c\u6210\u3057\u305f\u30bd\u30fc\u30b9<\/strong><\/p>\n\n\n\n<p>\u5b8c\u6210\u3057\u305f\u30bd\u30fc\u30b9\u304c\u3053\u3061\u3089<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import UIKit\nimport UserNotifications\nclass ViewController: UIViewController {\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Do any additional setup after loading the view, typically from a nib.\n\n        \/\/ \u901a\u77e5\u8a31\u53ef\u30c0\u30a4\u30a2\u30ed\u30b0\u3092\u8868\u793a\n        let center = UNUserNotificationCenter.current()\n        center.requestAuthorization(options: [.alert, .sound, .badge]) {\n            (granted, error) in\n            \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n        }\n\n        \/\/ \u901a\u77e5\u5185\u5bb9\u306e\u8a2d\u5b9a\n        let content = UNMutableNotificationContent()\n\n        content.title = NSString.localizedUserNotificationString(forKey: \"Title\", arguments: nil)\n        content.body = NSString.localizedUserNotificationString(forKey: \"Message\", arguments: nil)\n        content.sound = UNNotificationSound.default()\n\n        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)\n\n        let request = UNNotificationRequest(identifier: \" Identifier\", content: content, trigger: trigger)\n\n        \/\/ \u901a\u77e5\u3092\u767b\u9332\n        center.add(request) { (error : Error?) in\n            if error != nil {\n                \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\n            }\n        }\n\n    }\n\n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n        \/\/ Dispose of any resources that can be recreated.\n    }\n\n\n}\n\n\n<\/pre>\n\n\n\n<p>\u8aac\u660e\u4e0d\u8db3\u304c\u96a0\u3057\u304d\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u7d30\u304b\u3044\u3068\u3053\u308d\u306e\u7406\u89e3\u304c\u3067\u304d\u305f\u3089\u307e\u305f\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u901a\u77e5\u97f3\u3092\u518d\u751f\u21e8AVAudioPlayer\u306b\u5165\u308c\u308b\u21e8\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u7121\u9650\u30eb\u30fc\u30d7\u518d\u751f\u307f\u305f\u3044\u306a\u611f\u3058\u3067\u30a2\u30e9\u30fc\u30e0\u3092\u4f5c\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u306e\u304b\u306a\u3001\u3001\u3001<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u901a\u77e5\u3092\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3092\u81ea\u5206\u306e\u8a00\u8449\u3067\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002(Swift4) 1.\u30a4\u30f3\u30dd\u30fc\u30c8 2. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6105"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6105"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6105\/revisions"}],"predecessor-version":[{"id":6106,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6105\/revisions\/6106"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}