Swift 3D Touch iOS 10 Home Screen Quick Actions Share Item Missing

Swift 3D Touch iOS 10 Home screen quick actions share Item missing

That feature or option is only available for apps that are live on the App Store, it will not show up when testing your app. It is done automatically so there is nothing you will have to do.

3D Touch Quick actions not working at all

Looks like your app is Scene based. For Scene based apps you can almost forget about the AppDelegate and focus on the SceneDelegate. There are two methods you now need to override in the SceneDelegate and one in the AppDelegate. I'll mimic Apple's guide for clarity:

If the user is opening the app and it's a fresh launch, you handle this in the AppDelegate:

     // AppDelegate.swift
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.

// Grab a reference to the shortcutItem to use in the scene
if let shortcutItem = options.shortcutItem {
shortcutItemToProcess = shortcutItem
}

// Previously this method only contained the line below, where the scene is configured
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

If your app is still running in the background when the user clicks on the shortcut item, you handle that in the SceneDelegate:

    // SceneDelegate.swift
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
// When the user opens the app through a quick action, this is now the method that will be called
(UIApplication.shared.delegate as! AppDelegate).shortcutItemToProcess = shortcutItem
}

Once the scene is ready, you can do what you need to with the shortcut :

    // SceneDelegate.swift
func sceneDidBecomeActive(_ scene: UIScene) {
// Is there a shortcut item that has not yet been processed?
if let shortcutItem = (UIApplication.shared.delegate as! AppDelegate).shortcutItemToProcess {
// In this sample an alert is being shown to indicate that the action has been triggered,
// but in real code the functionality for the quick action would be triggered.
var message = "\(shortcutItem.type) triggered"
if let name = shortcutItem.userInfo?["Name"] {
message += " for \(name)"
}
let alertController = UIAlertController(title: "Quick Action", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Close", style: .default, handler: nil))
window?.rootViewController?.present(alertController, animated: true, completion: nil)

// Reset the shorcut item so it's never processed twice.
(UIApplication.shared.delegate as! AppDelegate).shortcutItemToProcess = nil
}
}

How to use 3D Touch to achieve sharing like this?

I actually asked that question the other day as well.

Swift 3D Touch iOS 10 Home screen quick actions share Item missing

This is a new iOS 10 feature that all apps got by default, so there is nothing you will have to do.
You will only see it on the version thats live on the app store, it will not show up when you are testing.

Which one of the App life cycle methods gets called when 3DTouch home screen quick actions are presented?

This is not possible, dynamic does not mean you can execute code at display of quick action. Your app can only setup dynamic quick actions after launch.

https://developer.apple.com/documentation/uikit/uiapplicationshortcutitem

Dynamic vs. Static Quick Actions
Although immutable, a UIApplicationShortcutItem instance is considered dynamic to distinguish it from a static quick action you specify at build time.
Define Home screen dynamic quick actions using this class. Your code creates dynamic quick actions, and registers them with your app object, at runtime.

Trying to get Static 3D touch Quick Actions to work in Obj-C

You also need to check the launchOptions in didFinishLaunchingWithOptions.

So, as the result of the ongoing chat, here's the latest code:

AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];

if(launchOptions)
{
UIApplicationShortcutItem *selectedItem = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];

if(selectedItem)
{
[self applyShortcutItem:selectedItem];
}
}
return YES;
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
[self applyShortcutItem:shortcutItem];
}

- (void)applyShortcutItem:(UIApplicationShortcutItem *)shortcutItem
{
ViewController *rootViewController = (ViewController *)[self.window rootViewController];

if([shortcutItem.type isEqualToString:@"DogModeShortcut"])
{
[rootViewController setShortcutAction:LaunchDogMode];
}
else if([shortcutItem.type isEqualToString:@"CatModeShortcut"])
{
[rootViewController setShortcutAction:LaunchCatMode];
}
}


Related Topics



Leave a reply



Submit