I am very new to the iOS Application development and I have been following tutorials to build my career . So starting with I am trying to Implement Static Quick Actions in Objective C as per client project . I was able to add the keys and got the options while pressing the icon . But when I press the Quick Actions nothing happens and it just launches the Application. I have researched a lot and I tried but in vain. Below is the Appdelegate code which I have written:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
BOOL shouldPerformAdditionalDelegateHandling = YES;
// Check API availiability
// UIApplicationShortcutItem is available in iOS 9 or later.
if([[UIApplicationShortcutItem class] respondsToSelector:@selector(new)]){
NSLog(@"HERE");
// [self configDynamicShortcutItems];
// If a shortcut was launched, display its information and take the appropriate action
UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKeyedSubscript:UIApplicationLaunchOptionsShortcutItemKey];
if(shortcutItem)
{
NSLog(@"shortcut launch");
// When the app launch at first time, this block can not called.
[self handleShortCutItem:shortcutItem];
// This will block "performActionForShortcutItem:completionHandler" from being called.
shouldPerformAdditionalDelegateHandling = NO;
}else{
NSLog(@"normal launch");
// normal app launch process without quick action
// [self launchWithoutQuickAction];
}
}else{
// Less than iOS9 or later
// [self launchWithoutQuickAction];
}
return shouldPerformAdditionalDelegateHandling;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
NSLog(@"performActionForShortcutItem");
BOOL handledShortCutItem = [self handleShortCutItem:shortcutItem];
completionHandler(handledShortCutItem);
}
/**
* @brief handle shortcut item depend on its type
*
* @param shortcutItem shortcutItem selected shortcut item with quick action.
*
* @return return BOOL description
*/
- (BOOL)handleShortCutItem : (UIApplicationShortcutItem *)shortcutItem{
BOOL handled = NO;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
if ([shortcutItem.type isEqualToString:@"PlayMusic"]) {
handled = YES;
NSLog(@"Play");
secondview *vc = [storyboard instantiateViewControllerWithIdentifier:@"second"];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
else if ([shortcutItem.type isEqualToString:@"StopMusic"]) {
handled = YES;
NSLog(@"Stop");
// ThirdViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"thirdVC"];
//
// self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
return handled;
}
However I can see the Quick Action items when I deep press the home icon but on clicking that no action happens. I check the key in info.plist and its the same .
Quick Actions
Below is the info.plist for adding Static Actions
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypePlay</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Play</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>Start playback</string>
<key>UIApplicationShortcutItemType</key>
<string>PlayMusic</string>
</dict>
<dict>
<key>UIApplicationShortcutItemIconType</key>
<string>UIApplicationShortcutIconTypePlay</string>
<key>UIApplicationShortcutItemTitle</key>
<string>STOP</string>
<key>UIApplicationShortcutItemSubtitle</key>
<string>Stop playback</string>
<key>UIApplicationShortcutItemType</key>
<string>StopMusic</string>
</dict>
Can some one please help where I am doing wrong?
2
Answers
since
iOS(13.0, *)
AppDelegate handles its ownUIWindow
viaSceneDelegate
‘s and so the methodis only invoked on iPhones or iPads with iOS lower Version 13.0
So to make it work in iOS(13.0,*) and above you need to implement it in SceneDelegate with a slightly different name, see below.. (matt was right!)
PS: The Apple Example Code for Quick Actions in swift is bogus when you assume you can use it as is in iOS(13.0,*) because it is written for versions earlier iOS < 13.0
EDIT: as asked, here in full beauty for iOS >= 13.0
and
You can do also other things than instantiate a ViewController from Storyboard. In example you could switch a property or something similar.
Sorry being too late. Further research about home quick actions showed me the following conclusions after discussing with major developers . The following points which needed to be followed while integrating HomeQuickActions are :
Both 3D touch enable and non-3D touch enabled devices support this feature through force-touch or long-press depending on device capabilities if they are capable of running iOS 13 or above.
So for App short cuts to work the iOS devices must be having iOS 13 for sure and the hardware compatibility is also required which means the devices must be having iOS 13 and above for App short cuts to work. For iPhone 5S, iPhone 6 owners: iOS 13 won’t be compatible anymore.
Since Apple has replaced 3D Touch hardware with Haptic Touch , the newer iPhones from iPhone XR will have only Haptic Touch . Old devices after SE(1 st generation, iPhone 6 series till iPhone X ) have 3D Touch hardware. Haptic Touch is a software OS dependent which uses finger pressed area and 3D Touch is a hardware dependent which uses a specific sensor between screen.