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

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

Maika Yamada
September 21, 2020
1.7k

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

Maika Yamada

September 21, 2020
Tweet

Transcript

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

    w "EEUP4JSJϘλϯ͔ΒΞϓϦΛ։͘γϣʔτΧοτΛొ࿥ͨ͠ w ճ਺ɿ  w ਓ਺ɿ 
  2. ࣮૷ *OGPQMJTUʹΞΫγϣϯͷ*%Λఆٛ <plist version="1.0"> <dict> <!-- தུ --> <key>NSUserActivityTypes</key> <array>

    <string>$(BUNDLE_ID).materialBarcodeRead</string> <string>$(BUNDLE_ID).viewQRCode</string> </array> </dict> </plist>
  3. ࣮૷ ֘౰ͷΞΫγϣϯΛߦ͏/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 } }
  4. ࣮૷ "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 } }
  5. ࣮૷ /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 }
  6. #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͔ΒͷఏҊ΁ͱͯ͠දࣔΛ༗ޮʹ͠ɺ දࣔ͢Δ஋Λઃఆ
  7. ࣮૷ ֘౰7JFX$POUSPMMFSΛ։͍ͨࡍʹ௨஌͢Δ final class MaterialBarcodeReaderViewController: UIViewController { override func viewDidLoad()

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

    { super.viewDidLoad() let activity = MaterialBarcodeReadAction.userActivity userActivity = activity activity.becomeCurrent() } } ࣮૷ࡁΈͷ/46TFS"DUJWJUJZΦϒδΣΫτͰ࠶ݱͰ͖Δ ૢ࡞Λͨ͜͠ͱΛ௨஌
  9. ࣮૷ ϘλϯΛ഑ஔ͢Δ 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) } }
  10. ࣮૷ ϘλϯΛ഑ஔ͢Δ 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ϘλϯΛԡԼͨ͠ࡍʹ ͜Ε͔Βදࣔ͢Δը໘ΦϒδΣΫτΛड͚औΔͨΊઃఆ
  11. ࣮૷ ϘλϯΛԡԼޙͷॲཧΛ࣮૷ 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) } }
  12. ࣮૷ 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) } }
  13. ࣮૷ 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) } }
  14. ఏҊϑϨʔζͱ͸ /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 } }
  15. ࢀߟ 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