From dd3f6db0cb3c242758ab0000a0513e093f02531c Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期四, 18 十一月 2021 13:11:32 +0800 Subject: [PATCH] 合并成功 --- SiriIntentsUI/Info.plist | 3 SiriIntents/Info.plist | 3 HDL-ON_iOS/Info.plist | 4 HDL-ON_iOS/Other/Siri/SiriBaseView.cs | 69 +++++++++++++ HDL-ON_iOS/Other/Siri/VoiceShortcutDataManager.cs | 57 +++++++++++ HDL-ON_iOS/HDL-ON_iOS.csproj | 2 HDL-ON_iOS/Other/Siri/SiriScene.cs | 100 ++++++++++++++++++++ .vs/HDL_APP_Project/xs/UserPrefs.xml | 24 ++-- HDL-ON_iOS/Other/SkipControl.cs | 12 -- 9 files changed, 248 insertions(+), 26 deletions(-) diff --git a/.vs/HDL_APP_Project/xs/UserPrefs.xml b/.vs/HDL_APP_Project/xs/UserPrefs.xml index 203c887..50014a3 100644 --- a/.vs/HDL_APP_Project/xs/UserPrefs.xml +++ b/.vs/HDL_APP_Project/xs/UserPrefs.xml @@ -3,32 +3,33 @@ <MonoDevelop.MacDev.AppleDevelopmentTeam /> </MonoDevelop.Ide.ItemProperties.SiriIntentUI> <MonoDevelop.Ide.ItemProperties.HDL-ON__iOS PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneDeviceTarget.6242be7109c740c6cb8999a8904b6e0ea8d45192" /> - <MonoDevelop.Ide.ItemProperties.SiriIntents FirstBuild="True"> + <MonoDevelop.Ide.ItemProperties.SiriIntents> <MonoDevelop.MacDev.AppleDevelopmentTeam /> </MonoDevelop.Ide.ItemProperties.SiriIntents> - <MonoDevelop.Ide.Workbench ActiveDocument="SiriIntents/IntentHandler.cs"> + <MonoDevelop.Ide.Workbench ActiveDocument="SiriBinding/obj/Debug/iOS/HdlSiri/HDLRunSceneIntent.g.cs"> <Files> <File FileName="HDL_ON/UI/UI1-Login/LoginPage.cs" Line="203" Column="35" /> - <File FileName="HDL-ON_iOS/Other/SkipControl.cs" Line="35" Column="1" /> - <File FileName="HDL-ON_iOS/Other/Siri/SiriBaseView.cs" Line="25" Column="2" /> - <File FileName="SiriBinding/ApiDefinition.cs" Line="8" Column="18" /> - <File FileName="SiriBinding/Structs.cs" Line="19" Column="1" /> - <File FileName="SiriIntents/IntentHandler.cs" Line="1" Column="1" /> + <File FileName="HDL-ON_iOS/Other/SkipControl.cs" Line="18" Column="36" /> + <File FileName="HDL-ON_iOS/Other/Siri/SiriBaseView.cs" Line="34" Column="101" /> + <File FileName="SiriBinding/Structs.cs" /> + <File FileName="SiriIntents/IntentHandler.cs" /> + <File FileName="HDL-ON_iOS/Other/Siri/VoiceShortcutDataManager.cs" Line="23" Column="45" /> + <File FileName="SiriBinding/obj/Debug/iOS/HdlSiri/HDLRunSceneIntent.g.cs" Line="63" Column="1" /> </Files> <Pads> <Pad Id="ProjectPad"> <State name="__root__"> <Node name="HDL_APP_Project" expanded="True"> - <Node name="SiriIntents" expanded="True"> - <Node name="IntentHandler.cs" selected="True" /> + <Node name="HDL-ON_iOS" selected="True" /> + <Node name="SiriBinding" expanded="True"> + <Node name="NativeReferenceFolder" expanded="True" /> </Node> - <Node name="SiriIntentsUI" expanded="True" /> </Node> </State> </Pad> </Pads> </MonoDevelop.Ide.Workbench> - <MonoDevelop.Ide.ItemProperties.SiriIntentsUI FirstBuild="True"> + <MonoDevelop.Ide.ItemProperties.SiriIntentsUI> <MonoDevelop.MacDev.AppleDevelopmentTeam /> </MonoDevelop.Ide.ItemProperties.SiriIntentsUI> <MonoDevelop.Ide.DebuggingService.PinnedWatches /> @@ -37,7 +38,6 @@ <String>Shared.Droid.TouchID/Shared.Droid.TouchID.csproj</String> <String>Shared.IOS/Shared.IOS.csproj</String> <String>SiriIntent/SiriIntent.csproj</String> - <String>SiriBinding/SiriBinding.csproj</String> </DisabledProjects> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.ItemProperties.HDL-ON__Android PreferredExecutionTarget="Android.SelectDevice" /> diff --git a/HDL-ON_iOS/HDL-ON_iOS.csproj b/HDL-ON_iOS/HDL-ON_iOS.csproj index 418934f..a817328 100644 --- a/HDL-ON_iOS/HDL-ON_iOS.csproj +++ b/HDL-ON_iOS/HDL-ON_iOS.csproj @@ -497,6 +497,8 @@ <Compile Include="Other\Siri\SiriBaseView.designer.cs"> <DependentUpon>SiriBaseView.cs</DependentUpon> </Compile> + <Compile Include="Other\Siri\VoiceShortcutDataManager.cs" /> + <Compile Include="Other\Siri\SiriScene.cs" /> </ItemGroup> <ItemGroup> <BundleResource Include="Resources\Phone\LoginIcon\ShowPasswordIcon.png" /> diff --git a/HDL-ON_iOS/Info.plist b/HDL-ON_iOS/Info.plist index d00fc31..a8ea6d3 100644 --- a/HDL-ON_iOS/Info.plist +++ b/HDL-ON_iOS/Info.plist @@ -135,5 +135,9 @@ <string>Make audio/video calls</string> <key>NSSiriUsageDescription</key> <string>On Pro data will be send to Siri.</string> + <key>NSUserActivityTypes</key> + <array> + <string>HDLRunSceneIntent</string> + </array> </dict> </plist> diff --git a/HDL-ON_iOS/Other/Siri/SiriBaseView.cs b/HDL-ON_iOS/Other/Siri/SiriBaseView.cs index e168dbd..bf375b9 100644 --- a/HDL-ON_iOS/Other/Siri/SiriBaseView.cs +++ b/HDL-ON_iOS/Other/Siri/SiriBaseView.cs @@ -1,10 +1,13 @@ 锘縰sing System; - +using CoreGraphics; +using Foundation; +using Intents; +using IntentsUI; using UIKit; namespace Other.Siri { - public partial class SiriBaseView : UIViewController + public partial class SiriBaseView : UIViewController, IINUIAddVoiceShortcutViewControllerDelegate, IINUIEditVoiceShortcutViewControllerDelegate { public SiriBaseView() : base("SiriBaseView", null) { @@ -14,6 +17,43 @@ { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. + + + + + var btn = UIButton.FromType(UIButtonType.System); + btn.Frame = new CGRect(20, 200, 280, 44); + btn.SetTitle("Click Me", UIControlState.Normal); + + + VoiceShortcutDataManager VoiceShortcutDataManager = new VoiceShortcutDataManager(); + btn.TouchUpInside += (sender, e) => + { + //HDL_ON_iOS.AppDelegate.rootViewController.SetNavigationBarHidden(HDL_ON_iOS.AppDelegate.rootViewController.NavigationBarHidden ? false : true, true); + var ss = new SiriScene() { Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString() }; + //INVoiceShortcut existingShortcut = VoiceShortcutDataManager?.VoiceShortcutForOrder(ss); + //if (!(existingShortcut is null)) + //{ + // var editVoiceShortcutViewController = new INUIEditVoiceShortcutViewController(existingShortcut); + // editVoiceShortcutViewController.Delegate = this; + // PresentViewController(editVoiceShortcutViewController, true, null); + //} + //else + { + // Since the app isn't yet managing a voice shortcut for + // this order, present the add view controller + INShortcut newShortcut = new INShortcut(ss.Intent); + if (!(newShortcut is null)) + { + var addVoiceShortcutVC = new INUIAddVoiceShortcutViewController(newShortcut); + addVoiceShortcutVC.Delegate = this; + PresentViewController(addVoiceShortcutVC, true, null); + } + } + + }; + + View.AddSubview(btn); } public override void DidReceiveMemoryWarning() @@ -21,6 +61,31 @@ base.DidReceiveMemoryWarning(); // Release any cached data, images, etc that aren't in use. } + + public void DidFinish(INUIAddVoiceShortcutViewController controller, INVoiceShortcut voiceShortcut, NSError error) + { + Console.WriteLine("didF"); + } + + public void DidCancel(INUIAddVoiceShortcutViewController controller) + { + Console.WriteLine("didC"); + } + + public void DidUpdate(INUIEditVoiceShortcutViewController controller, INVoiceShortcut voiceShortcut, NSError error) + { + Console.WriteLine("didU"); + } + + public void DidDelete(INUIEditVoiceShortcutViewController controller, NSUuid deletedVoiceShortcutIdentifier) + { + Console.WriteLine("didD"); + } + + public void DidCancel(INUIEditVoiceShortcutViewController controller) + { + Console.WriteLine("didC"); + } } } diff --git a/HDL-ON_iOS/Other/Siri/SiriScene.cs b/HDL-ON_iOS/Other/Siri/SiriScene.cs new file mode 100644 index 0000000..8dcb815 --- /dev/null +++ b/HDL-ON_iOS/Other/Siri/SiriScene.cs @@ -0,0 +1,100 @@ +锘縰sing System; +using Foundation; +using HdlSiri; +using Intents; +using UIKit; + +namespace Other.Siri +{ + public class SiriScene : NSObject , INSCoding + { + public SiriScene() + { + } + + public string Id; + + public string Name; + + public void EncodeTo(NSCoder encoder) + { + Console.WriteLine("nscoder"); + } + + public HDLRunSceneIntent Intent + { + get + { + var orderSoupIntent = new HDLRunSceneIntent() { SceneId = Id, SceneName = Name }; + //orderSoupIntent.Quantity = new NSNumber(Quantity); + //orderSoupIntent.Soup = new INObject(MenuItem.ItemNameKey, MenuItem.LocalizedString); + + //var image = UIImage.FromBundle(MenuItem.IconImageName); + //if (!(image is null)) + //{ + // var data = image.AsPNG(); + // orderSoupIntent.SetImage(INImage.FromData(data), "soup"); + //} + + //orderSoupIntent.Options = MenuItemOptions + // .ToArray<MenuItemOption>() + // .Select<MenuItemOption, INObject>(arg => new INObject(arg.Value, arg.LocalizedString)) + // .ToArray<INObject>(); + + //var comment = "Suggested phrase for ordering a specific soup"; + //var phrase = NSBundleHelper.SoupKitBundle.GetLocalizedString("ORDER_SOUP_SUGGESTED_PHRASE", comment); + //orderSoupIntent.SuggestedInvocationPhrase = String.Format(phrase, MenuItem.LocalizedString); + + return orderSoupIntent; + } + } + + public static SiriScene FromOrderSoupIntent(HDLRunSceneIntent intent) + { + //var menuManager = new SoupMenuManager(); + + //var soupID = intent.Soup?.Identifier; + //if (soupID is null) + //{ + // return null; + //} + + //var menuItem = menuManager.FindItem(soupID); + //if (menuItem is null) + //{ + // return null; + //} + + //var quantity = intent.Quantity; + //if (menuItem is null) + //{ + // return null; + //} + + //MenuItemOption[] rawOptions; + //if (intent.Options is null) + //{ + // rawOptions = new MenuItemOption[0]; + //} + //else + //{ + // // For the equivalent code in Apple's Swift sample, compactMap + // // is used. This eliminates nil values from the final result. + // // Here, LINQ's Where method is used to filter out the null + // // values. + // rawOptions = intent.Options.Select<INObject, MenuItemOption>((option) => + // { + // var optionID = option.Identifier; + // return (optionID is null) ? null : new MenuItemOption(optionID); + // }).Where((option) => !(option is null)).ToArray<MenuItemOption>(); + //} + + //var order = new Order(quantity.Int32Value, menuItem, new NSMutableSet<MenuItemOption>(rawOptions)); + + //return order; + return null; + } + + + } +} diff --git a/HDL-ON_iOS/Other/Siri/VoiceShortcutDataManager.cs b/HDL-ON_iOS/Other/Siri/VoiceShortcutDataManager.cs new file mode 100644 index 0000000..041374d --- /dev/null +++ b/HDL-ON_iOS/Other/Siri/VoiceShortcutDataManager.cs @@ -0,0 +1,57 @@ +锘�/* +See LICENSE folder for this sample鈥檚 licensing information. + +Abstract: +A data manager that surfaces INVoiceShortcuts managed by INVoiceShortcutCenter. +*/ + +using System; +using Intents; +using System.Linq; + +namespace Other.Siri +{ + public class VoiceShortcutDataManager + { + INVoiceShortcut[] VoiceShortcuts; + + public VoiceShortcutDataManager() + { + UpdateVoiceShortcuts(null); + } + + public INVoiceShortcut VoiceShortcutForOrder(SiriScene ss) + { + var voiceShortcut = VoiceShortcuts.FirstOrDefault((shortcut) => + { + var intent = shortcut.Shortcut.Intent as HdlSiri.HDLRunSceneIntent; + if (intent is null) { return false; } + var orderFromIntent = SiriScene.FromOrderSoupIntent(intent); + if (orderFromIntent is null) { return false; } + return ss.IsEqual(orderFromIntent); + }); + return voiceShortcut; + } + + public void UpdateVoiceShortcuts(Action completion) + { + INVoiceShortcutCenter.SharedCenter.GetAllVoiceShortcuts((voiceShortcutsFromCenter, error) => + { + if (voiceShortcutsFromCenter is null) + { + if (!(error is null)) + { + Console.WriteLine($"Failed to fetch voice shortcuts with error {error}"); + } + return; + } + VoiceShortcuts = voiceShortcutsFromCenter; + if (!(completion is null)) + { + completion(); + } + }); + } + + } +} diff --git a/HDL-ON_iOS/Other/SkipControl.cs b/HDL-ON_iOS/Other/SkipControl.cs index dc94297..408138f 100644 --- a/HDL-ON_iOS/Other/SkipControl.cs +++ b/HDL-ON_iOS/Other/SkipControl.cs @@ -1,5 +1,7 @@ 锘縰sing System; using CoreGraphics; +using Intents; +using IntentsUI; using Other.Siri; using UIKit; @@ -16,21 +18,11 @@ var user = new SiriBaseView(); user.View.BackgroundColor = UIColor.Magenta; - var btn = UIButton.FromType(UIButtonType.System); - btn.Frame = new CGRect(20, 200, 280, 44); - btn.SetTitle("Click Me", UIControlState.Normal); - - HDL_ON_iOS.AppDelegate.rootViewController.NavigationBarHidden = true; HDL_ON_iOS.AppDelegate.rootViewController.NavigationBarHidden = false; HDL_ON_iOS.AppDelegate.rootViewController.PushViewController(user, true); - btn.TouchUpInside += (sender, e) => - { - HDL_ON_iOS.AppDelegate.rootViewController.SetNavigationBarHidden(HDL_ON_iOS.AppDelegate.rootViewController.NavigationBarHidden ? false : true, true); - }; - user.View.AddSubview(btn); } } } diff --git a/SiriIntents/Info.plist b/SiriIntents/Info.plist index bf03fa4..63023d3 100644 --- a/SiriIntents/Info.plist +++ b/SiriIntents/Info.plist @@ -1,4 +1,4 @@ -锘�<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> @@ -31,6 +31,7 @@ <string>INSendMessageIntent</string> <string>INSearchForMessagesIntent</string> <string>INSetMessageAttributeIntent</string> + <string>HDLRunSceneIntent</string> </array> </dict> <key>NSExtensionPointIdentifier</key> diff --git a/SiriIntentsUI/Info.plist b/SiriIntentsUI/Info.plist index 269af89..b9e141f 100644 --- a/SiriIntentsUI/Info.plist +++ b/SiriIntentsUI/Info.plist @@ -1,4 +1,4 @@ -锘�<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> @@ -27,6 +27,7 @@ <key>IntentsSupported</key> <array> <string>INSendMessageIntent</string> + <string>HDLRunSceneIntent</string> </array> </dict> <key>NSExtensionMainStoryboard</key> -- Gitblit v1.8.0