Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS 13におけるSiri Shortcuts 最小実装+α

D0337ede0237cdaff325101c71617a3b?s=47 Maika Yamada
September 21, 2020
1.2k

iOS 13におけるSiri Shortcuts 最小実装+α

D0337ede0237cdaff325101c71617a3b?s=128

Maika Yamada

September 21, 2020
Tweet

Transcript

  1. J04%$+BQBOEBZ ໌౉ຑҥՖ !N@ZBNBEB J04ʹ͓͚Δ4JSJ4IPSUDVUT ࠷খ࣮૷ Ћ

  2. ࣗݾ঺հ w ໌౉ຑҥՖ w 5XJUUFS!N@ZBNBEB w 4UVEZQMVT *OD w ʙ

    w ࣄ຿৬ˠ4*FSˠݱࡏ w J04&OHJOFFS
  3.  4JSJ4IPSUDVUTػೳΛϦϦʔε ͋ͳͨͷؤுΓΛݟ͑ΔԽ͢Δษڧه࿥ΞϓϦ 4UVEZQMVT

  4. ରԠͨ͠ը໘ w Ϣʔβʔͷ23ίʔυը໘ w ॻ੶ͷόʔίʔυಡΈऔΓΧϝ ϥը໘ ͦΕͧΕɺ"QQMF͕4JSJ4IPSUDVUT ͷ࣮૷ΛקΊΔΞϓϦΛར༻͢Δ ্ͰԿճ΋܁Γฦ͠ߦΘΕΔૢ࡞ ʹ֘౰͢Δͱ൑அ࣮ͯ͠૷

  5. 4JSJ4IPSUDVUTར༻ঢ়گ ˞೥݄೔ʙ݄೔࣌఺ w γϣʔτΧοτܦ༝ͰΞϓϦΛ։͍ͨ w ճ਺ɿ  w ਓ਺ɿ 

    w "EEUP4JSJϘλϯ͔ΒΞϓϦΛ։͘γϣʔτΧοτΛొ࿥ͨ͠ w ճ਺ɿ  w ਓ਺ɿ 
  6. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  7. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  8. ࠷খ࣮૷ͱ͸ 4JSJ4IPSUDVUTࣗମʹ࣮૷ํ๏͕େ͖͘௨Γ͋Δ w *OUFOUT*OUFOUT6*Λ༻͍Δ w ΞϓϦʹͯ܁Γฦ͠ߦ͏ಈ࡞Λ༷ʑͳ஋Λड͚औΓͭͭ࠶ݱՄೳ w /46TFS"DUJWJUZΛ༻͍Δ w ಛఆͷը໘Λ։͍ͨঢ়ଶͷΞϓϦΛىಈ͢ΔͳͲɺ୯७ͳಈ࡞Λ࠶ݱՄೳ

  9. ࠷খ࣮૷ͱ͸ 4JSJ4IPSUDVUTࣗମʹ࣮૷ํ๏͕େ͖͘௨Γ͋Δ w *OUFOUT*OUFOUT6*Λ༻͍Δ w ΞϓϦʹͯ܁Γฦ͠ߦ͏ಈ࡞Λ༷ʑͳ஋Λड͚औΓͭͭ࠶ݱՄೳ w /46TFS"DUJWJUZΛ༻͍Δ w ಛఆͷը໘Λ։͍ͨঢ়ଶͷΞϓϦΛىಈ͢ΔͳͲɺ୯७ͳಈ࡞Λ࠶ݱՄೳ

  10. ࣮૷ *OGPQMJTUʹΞΫγϣϯͷ*%Λఆٛ <plist version="1.0"> <dict> <!-- தུ --> <key>NSUserActivityTypes</key> <array>

    <string>$(BUNDLE_ID).materialBarcodeRead</string> <string>$(BUNDLE_ID).viewQRCode</string> </array> </dict> </plist>
  11. ࣮૷ ֘౰ͷΞΫγϣϯΛߦ͏/46TFS"DUJWJUZΦϒδΣΫτΛੜ੒ ˞ҎԼ͸όʔίʔυಡΈऔΓΧϝϥը໘༻ͷΦϒδΣΫτੜ੒ॲཧ import Intents struct MaterialBarcodeReadAction { static var

    actionName: String { return "\(bundleId).materialBarcodeRead" } static var userActivity: NSUserActivity { let userActivity = NSUserActivity(activityType: actionName) userActivity.persistentIdentifier = actionName userActivity.title = "ڭࡐͷόʔίʔυΛಡΈऔΔ" return userActivity } }
  12. ࣮૷ ֘౰ͷΞΫγϣϯͰ։͘6*7JFX$POUSPMMFS΁ΦϒδΣΫτΛઃఆ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity } }
  13. ࣮૷ "QQ%FMFHBUFʹϋϯυϧ࣌ͷॲཧΛ࣮૷ func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler:

    @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { switch userActivity.activityType { case MaterialBarcodeReadAction.actionName: // όʔίʔυಡΈऔΓΧϝϥը໘දࣔ return true case ViewQRCodeAction.actionName: // QRίʔυը໘දࣔ return true default: return false } }
  14. ࠷খ࣮૷·Ͱࡁ·ͤΔͱʜ ˠlγϣʔτΧοτzΞϓϦʹͯར༻ՄೳͳΞΫγϣϯͱͯ͠બ୒ࢶ͕දࣔ͞ΕΔ ˞4JSJ4IPSUDVUT࣮૷ͨ͠ޙͷର৅ը໘ΛճҎ্։͍͍ͯΔඞཁ͋Γ

  15. γϣʔτΧοτͷొ࿥ํ๏ J04࣌఺

  16. None
  17. γϣʔτΧοτΪϟϥϦʔ͔Β΋ొ࿥Մೳ

  18. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  19. ࣮૷ /46TFS"DUJWJUZΦϒδΣΫτʹͯఏҊʹࡌͤΔ஋Λઃఆ #if canImport(CoreSpotlight) import CoreSpotlight import MobileCoreServices #endif /*

    লུ */ static var userActivity: NSUserActivity { let userActivity = NSUserActivity(activityType: actionName) userActivity.persistentIdentifier = actionName userActivity.title = "ڭࡐͷόʔίʔυΛಡΈऔΔ" userActivity.isEligibleForPrediction = true #if canImport(CoreSpotlight) let attributes = CSSearchableItemAttributeSet(itemContentType: kUTTypeContent as String) attributes.title = "ڭࡐͷόʔίʔυΛಡΈऔΔ" attributes.contentDescription = "ొ࿥͍ͨ͠ڭࡐͷόʔίʔυΛಡΈऔΕ·͢" userActivity.contentAttributeSet = attributes #endif return userActivity }
  20. #if canImport(CoreSpotlight) import CoreSpotlight import MobileCoreServices #endif /* লུ */

    static var userActivity: NSUserActivity { let userActivity = NSUserActivity(activityType: actionName) userActivity.persistentIdentifier = actionName userActivity.title = "ڭࡐͷόʔίʔυΛಡΈऔΔ" userActivity.isEligibleForPrediction = true #if canImport(CoreSpotlight) let attributes = CSSearchableItemAttributeSet(itemContentType: kUTTypeContent as String) attributes.title = "ڭࡐͷόʔίʔυΛಡΈऔΔ" attributes.contentDescription = "ొ࿥͍ͨ͠ڭࡐͷόʔίʔυΛಡΈऔΕ·͢" userActivity.contentAttributeSet = attributes #endif return userActivity } ࣮૷ /46TFS"DUJWJUZΦϒδΣΫτʹͯఏҊʹࡌͤΔ஋Λઃఆ *NQPSUΛ௥Ճ 4QPUMJHIUͰ4JSJ͔ΒͷఏҊ΁ͱͯ͠දࣔΛ༗ޮʹ͠ɺ දࣔ͢Δ஋Λઃఆ
  21. ࣮૷ ֘౰7JFX$POUSPMMFSΛ։͍ͨࡍʹ௨஌͢Δ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity activity.becomeCurrent() } }
  22. ࣮૷ ֘౰7JFX$POUSPMMFSΛ։͍ͨࡍʹ௨஌͢Δ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity activity.becomeCurrent() } } ࣮૷ࡁΈͷ/46TFS"DUJWJUJZΦϒδΣΫτͰ࠶ݱͰ͖Δ ૢ࡞Λͨ͜͠ͱΛ௨஌
  23. ௨஌ͷ࣮૷·Ͱࡁ·ͤΔͱʜ ˠ֘౰ͷը໘ΛΑ͘࢖͏৔߹ɺ ɹl4JSJ͔ΒͷఏҊzʹදࣔ͞ΕΔ ˞બ୒͢Δͱɺը໘ʹભҠ͢Δ͕γϣʔτΧοτ ͷ௥Ճ͸ෆՄ ˞σόοάʹ͸ɺ୺຤ͷઃఆσϕϩού %JTQMBZ3FDFOU4IPSUDVUTΛ0/

  24. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  25. ࣮૷ ϘλϯΛ഑ஔ͢Δ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity activity.becomeCurrent() let addToSiriButton = INUIAddVoiceShortcutButton(style: .automaticOutline) addToSiriButton.shortcut = INShortcut(userActivity: activity) addToSiriButton.delegate = self view.addSubview(addToSiriButton) } }
  26. ࣮૷ ϘλϯΛ഑ஔ͢Δ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity activity.becomeCurrent() let addToSiriButton = INUIAddVoiceShortcutButton(style: .automaticOutline) addToSiriButton.shortcut = INShortcut(userActivity: activity) addToSiriButton.delegate = self view.addSubview(addToSiriButton) } } "EEUP4JSJϘλϯͷΦϒδΣΫτΛੜ੒ γϣʔτΧοτͱͯ͠ొ࿥͢Δૢ࡞ "EEUP4JSJϘλϯΛԡԼͨ͠ࡍʹ ͜Ε͔Βදࣔ͢Δը໘ΦϒδΣΫτΛड͚औΔͨΊઃఆ
  27. ࣮૷ ϘλϯΛԡԼޙͷॲཧΛ࣮૷ extension MaterialBarcodeReaderViewController: INUIAddVoiceShortcutButtonDelegate { func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController,

    for addVoiceShortcutButton: INUIAddVoiceShortcutButton) { addVoiceShortcutViewController.delegate = self present(addVoiceShortcutViewController, animated: true, completion: nil) } func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) { editVoiceShortcutViewController.delegate = self present(editVoiceShortcutViewController, animated: true, completion: nil) } }
  28. None
  29. ࣮૷ 4JSJ4IPSUDVUTͷ௥Ճɾฤू׬ྃ࣌ͷॲཧΛ࣮૷ ௥Ճ extension MaterialBarcodeReaderViewController: INUIAddVoiceShortcutViewControllerDelegate { func addVoiceShortcutViewController( _

    controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) { controller.dismiss(animated: true, completion: nil) } func addVoiceShortcutViewControllerDidCancel( _ controller: INUIAddVoiceShortcutViewController) { controller.dismiss(animated: true, completion: nil) } }
  30. ࣮૷ 4JSJ4IPSUDVUTͷ௥Ճɾฤू׬ྃ࣌ͷॲཧΛ࣮૷ ฤू extension MaterialBarcodeReaderViewController: INUIEditVoiceShortcutViewControllerDelegate { func editVoiceShortcutViewController( _

    controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) { controller.dismiss(animated: true, completion: nil) } func editVoiceShortcutViewController( _ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) { controller.dismiss(animated: true, completion: nil) } func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) { controller.dismiss(animated: true, completion: nil) } }
  31. "EEUP4JSJϘλϯ͕͋Δͱʜ ˠࣗ෼ͷΞϓϦ͔Β4JSJγϣʔτΧοτΛ௥Ճ͢Δಋઢ͕Ͱ͖Δ ˠ࣮ࡍʹͦͷը໘ΛΑ͘ར༻͢ΔϢʔβʔ͕ݟ͚ͭ΍͘͢ͳΔ

  32. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  33. "EEUP4JSJϘλϯΛ ഑ஔ͢ΔͱΑ͍ը໘ w ഑ஔ͢Δ͜ͱͰຊདྷͷ໾ׂΛશ͏͢Δͷʹࢧো͕ग़ͳ͍ w ΋ͱ΋ͱ༨ന͕े෼ʹ͋ΓɺӬଓతʹදࣔ͠ଓ͚ͯ΋໰୊ͳ͍ w Ϋογϣϯϖʔδͱͯ͠ผը໘ΛڬΉܗͰදࣔͯ͠΋ࠩ͠ࢧ͑ͳ͍ ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w

    ഑ஔ͢Δͱຊདྷͷ໾ׂΛશ͏͢ΔͨΊͷྖҬ͕ڱ͘ͳΔը໘ w ༷ʑͳ৘ใΛݟΔͨΊͷը໘ͳͲ
  34. ΞδΣϯμ w 4JSJ4IPSUDVUT࠷খ࣮૷ w 4QPUMJHIUͷl4JSJ͔ΒͷఏҊzʹγϣʔτΧοτΛࡌͤΔ w "EEUP4JSJϘλϯΛ഑ஔ͢Δ w ࣮૷ͯ͠Έͨ͏͑Ͱͷࢲతߟ࡯ w

    "EEUP4JSJϘλϯΛ഑ஔ͢ΔͱΑ͍ը໘ɺ഑ஔ͠ͳ͍΄͏͕Α͍ը໘ w ఏҊϑϨʔζͷબͼ͔ͨ
  35. ఏҊϑϨʔζͱ͸ /46TFS"DUJWJUZͷTVHHFTUFE*OWPDBUJPO1ISBTF import Intents struct MaterialBarcodeReadAction { static var actionName:

    String { return "\(bundleId).materialBarcodeRead" } static var userActivity: NSUserActivity { let userActivity = NSUserActivity(activityType: actionName) userActivity.persistentIdentifier = actionName userActivity.title = “ڭࡐͷόʔίʔυΛಡΈऔΔ” userActivity.suggestedInvocationPhrase = "όʔίʔυΛಡΈऔΔ" return userActivity } }
  36. ఏҊϑϨʔζ͕දࣔ͞ΕΔ৔ॴ w "EEUP4JSJϘλϯԡԼޙ w γϣʔτΧοτΪϟϥϦʔܦ༝ ͰͷγϣʔτΧοτొ࿥ Ի੠ίϚϯυཝͷσϑΥϧτ஋ɻೖΕ ͓ͯ͘ͱϢʔβʔ͸ࣗ෼ͰʮԿͯݺͼ ͔͚Α͏ʁʯͱߟ͑ΔखؒΛল͍ͯొ ࿥Ͱ͖ͯศར

  37. ఏҊϑϨʔζ͕දࣔ͞ΕΔ৔ॴ w "EEUP4JSJϘλϯԡԼޙ w γϣʔτΧοτΪϟϥϦʔܦ༝ ͰͷγϣʔτΧοτొ࿥ Ի੠ίϚϯυཝͷσϑΥϧτ஋ɻೖΕ ͓ͯ͘ͱϢʔβʔ͸ࣗ෼ͰʮԿͯݺͼ ͔͚Α͏ʁʯͱߟ͑ΔखؒΛল͍ͯొ ࿥Ͱ͖ͯศར

    ˠ4JSJ͕ฉ͖औΓͮΒ͍ݴ༿ɺϢʔβʔ͕࢖͍ʹ͍͘ݴ༿ΛΛઃఆͯ͠͠·͏ͱɺ࢖ΘΕͳ͘ͳΔ
  38. ΑΓϢʔβʔ͕ར༻͠΍͍͢ ϑϨʔζΛબͿʹ͸ʁ

  39. w ଞΞϓϦͷγϣʔτΧοτͱॏෳ͠ͳ͍ w ݕূ͢Δ୺຤ w ݕূ͢Δ؀ڥ

  40. ଞΞϓϦͷྨࣅγϣʔτΧοτͱॏෳͤ͞ͳ͍ w ಉ͡୺຤಺ʹڞଘ͍ͯ͠ΔՄೳੑ͕ߴ͍ΞϓϦͷγϣʔτΧοτΛ֬ೝ w ྨࣅͷγϣʔτΧοτ͕͋Δ৔߹ɺڞଘͯ͠΋ݺͼ෼͚Ͱ͖ΔΑ͏ΞϓϦ ໊ΛؚΊΔͷ͕Φεεϝ w ΞϓϦ໊͸༏ઌͯ͠ฉ͖औΓͯ͘͠ΕΔ༷ࢠ w ΞϓϦ໊Ͱ΋ུশͳͲ͸ཁݕূ

  41. ݕূ͢Δ୺຤ w αϙʔτ͍ͯ͠Δ04όʔδϣϯͷ͏ͪɺҰ൪௿͍ϝδϟʔόʔδϣϯͷ୺຤ Ͱ֬ೝ w 04όʔδϣϯ͕ਐΉຖʹฉ͖औΓੑೳ͕େ͖͘޲্͍ͯ͠Δ w αϙʔτ͍ͯ͠Δ04όʔδϣϯͷൣғͰۃྗεϖοΫͷ௿͍୺຤Ͱ֬ೝ w ϋʔυ໘Ͱ΋ฉ͖औΓੑೳ͕ҟͳΔ

  42. ݕূ͢Δ؀ڥ w Ͱ͖Δ͚ͩϢʔβʔ͕࣮ࡍʹར༻͠͏Δ؀ڥʹ͍ۙঢ়ଶͰࢼ͢ w εϙʔπδϜͰར༻͢ΔΞϓϦͳΒ࣮ࡍʹ͍͖࣋ͬͯฉ͖औΓΛࢼ͢ͳͲ w صͷ্ʹฏஔ͖ͨ͠ঢ়ଶͰࢼ͢ w ֯౓΍୺຤΁ͷ઀஍໘ͷ౎߹͔Β͔ɺखͰ࣋ͭΑΓҙਤ͠ͳ͍ࡶԻ͕रΘ Ε͕ͪ

  43. Α͍4JSJ4IPSUDVUTରԠΛ

  44. ࢀߟ /46TFS"DUJWJUZUJUMF /46TFS"DUJWJUZDPOUFOU"UUSJCVUF4FUDPOUFOU%FTDSJQUJPO γϣʔτΧοτ 4JSJ͔ΒͷఏҊ 4JSJʹ௥Ճ /46TFS"DUJWJUZDPOUFOU"UUSJCVUF4FUUIVNCOBJM%BUB /46TFS"DUJWJUZTVHHFTUFE*OWPDBUJPO1ISBTF ᶃ ᶃ

    ᶃ ᶃ ᶃ ᶄ ᶄ ᶄ ᶅ ᶅ ᶅ ᶅ ᶅ ᶆ ᶆ
  45. ࢀߟ w "EEJOH6TFS*OUFSBDUJWJUZXJUI4JSJ4IPSUDVUTBOEUIF4IPSUDVUT"QQ w IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOTJSJLJU BEEJOH@VTFS@JOUFSBDUJWJUZ@XJUI@TJSJ@TIPSUDVUT@BOE@UIF@TIPSUDVUT@BQ Q w %FTJHOJOH(SFBU4IPSUDVUT w

    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED
  46. ࢀߟ w 4PVQ$IFG αϯϓϧίʔυ  w IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOTJSJLJU TPVQ@DIFG@BDDFMFSBUJOH@BQQ@JOUFSBDUJPOT@XJUI@TIPSUDVUT w 4JSJ4IPSUDVUT·ͱΊ

    w IUUQTLVSPIBUFOBCMPHDPNFOUSZ w J1IPOF΍J1BEͰγϣʔτΧοτ"QQΛ࢖͏c"QQMF w IUUQTTVQQPSUBQQMFDPNKBKQ)5