Can Siri be invoked programmatically within my app using private APIs?
The answer depends a bit on whether this is for an app that just won't go to the App Store (enterprise app, or personal/hobby app), or whether it will actually be run on jailbroken phones.
If you can rely on a jailbroken phone, and jailbreak utilities like MobileSubstrate, then I believe you can implement a method to open Siri just like Ryan Petrich's libActivator does, as I show in this other answer.
However, if you are building for normal, jailed phones, I still think you can "hack" it (with Private APIs), by simulating the way the user opens Siri. First, press the Home button, hold it for a bit, then release it.
This code works for me (iOS 6.1):
#import "GSEvent.h"
and
- (void)launchSiri {
[self simulateTouchEvent: kGSEventMenuButtonDown];
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self simulateTouchEvent: kGSEventMenuButtonUp];
});
}
- (void)simulateTouchEvent: (GSEventType)type
{
struct GSEventRecord record;
memset(&record, 0, sizeof(record));
record.type = type;
record.timestamp = GSCurrentEventTimestamp();
GSSendSystemEvent(&record);
}
This relies on having the GSEvent.h header, which isn't part of the public set of headers. I believe I got mine here, as well as GSWindow.h that it pulls in. Obviously, you'd then need to download these two headers and add them to your project.
This code is in the GraphicsServices private framework, so you'll also need to add that framework to your project. Do so just like adding a normal framework, but you need to browse to somewhere like
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework
to find it (path adjusted for your Xcode installation directory, and SDK).
Disclaimer: I did test this on a jailbroken phone, but it was definitely inside a normal app, installed in the /var/mobile/Applications/
sandbox area, and I'm 99% sure I haven't done anything that depends on being jailbroken.
How to activate Siri programmatically?
You can not invoke Siri programmatically in any iOS version at the moment.
Depending on your use case, you can use SFSpeechRecognizer
to recognize the users speech or use SiriKit
to accomplish a task using Siri.
Disabling Siri in an app
No. It's impossible to override the functionality of the home button. In general, Apple does not allow you to modify the behavior of something that is outside of the scope of your app.
Related Topics
"Interfaceorientation" Is Deprecated in iOS 8, How to Change This Method Objective C
Tableview Reloaddata VS. Beginupdates & Endupdates
Can't Prevent 'Touchmove' from Scrolling Window on iOS
Nstimer - How to Delay in Swift
Get iOS Itunes App Store Id of an App Itself
How to Check If a Uialertcontroller Is Already Presenting
Swiftui: Unwanted Split View on iPad
How to Disable Caching from Nsurlsessiontask
How to Push Two View Controllers But Animate Transition Only for the Second One
Pod Error in Xcode "Id: Framework Not Found Pods"
Spacing Between Uitableviewcells
iOS Tab Bar Icons Keep Getting Larger
Facebooksdk and Bolts Conflicting Each Other (Duplicate Symbols) on Build
Detect If Swift App Is Being Run from Xcode
Xcode 9 - Localization Issue Warning Storyboard