Swift wrapper for iOS Home Screen Quick Actions (App Icon Shortcuts)

Overview

Carthage Compatible CocoaPods Compatible Swift 5.0 Platforms iOS License MIT

QuickActions

Swift wrapper for iOS Home Screen Quick Actions

This wrapper creates dynamic quick actions. It is possible to define static quick actions in your app’s Info.plist file but I think it is nicer to add localizable shortcuts dynamically and handle them with type safety.

Usage

import QuickActions

Define your application shortcuts with an enum. Don't forget to declare the enum with String and ShortcutType:

enum AppShortcut: String, ShortcutType {
    case createExpense
    case lastItems
}

Install a list of shortcuts:

var quickActions: QuickActions<AppShortcut>?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    let shortcuts = [Shortcut(type: AppShortcut.CreateExpense, title: NSLocalizedString("CreateExpenseTitle", comment: ""), subtitle: NSLocalizedString("CreateExpenseSubTitle", comment: ""), icon: .Add)]

    if let actionHandler = window?.rootViewController as? QuickActionSupport, bundleIdentifier = Bundle.main.bundleIdentifier {
        quickActions = QuickActions(application, actionHandler: actionHandler, bundleIdentifier: bundleIdentifier, shortcuts: shortcuts, launchOptions: launchOptions)
    }
}

Add more shortcuts:

func applicationDidEnterBackground(application: UIApplication) {
    let shortcuts = [Shortcut(type: AppShortcut.lastItems, title: "Last items", subtitle: nil, icon: nil)]
    quickActions?.add(shortcuts, toApplication: application)
}

Handle each shortcut:

@available(iOS 9, *)
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Swift.Void) {
    // This callback is used if your application is already launched in the background, if not application(_:,willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions) will be called (handle the shortcut in those callbacks and return `false`)
    guard let quickActions = quickActions else {
        return completionHandler(false)
    }
    guard let actionHandler = window?.rootViewController as? QuickActionSupport else {
        return completionHandler(false)
    }
    completionHandler(quickActions.handle(actionHandler, shortcutItem: shortcutItem))
}

Prepare your view controller using the QuickActionSupport protocol:

class MainViewController: UIViewController, QuickActionSupport {

    func prepareForQuickAction<T: ShortcutType>(_ shortcutType: T) {
        if let shortcut = AppShortcut(rawValue: shortcutType.value), case .createExpense = shortcut {
            print("Prepare the view to create a new expense")
        }

        //or

        if let shortcut = AppShortcut(rawValue: shortcutType.value) {
            switch shortcut {
            case .createExpense:
                print("Prepare the view to create a new expense")
            case .lastItems:
                print("Prepare the view to show last items")
            }
        }
    }    

}

Installation

Carthage

To install it, simply add the following line to your Cartfile:

github "ricardopereira/QuickActions" ~> 6.0.0

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

CocoaPods

To install it, simply add the following line to your Podfile:

pod 'QuickActions' '~> 6.0.0'

You will also need to make sure you're opting into using frameworks:

use_frameworks!

Then run pod install with CocoaPods 1.8.0 or newer.

Manually

  1. Download and drop QuickActions.swift in your project.
  2. Congratulations!

Requirements

  • iOS 10.0+
  • Xcode 11.0 (Swift 5)

Author

Ricardo Pereira, @ricardopereiraw

License

QuickActions is available under the MIT license. See the LICENSE file for more info.

You might also like...
TTGSnackbar shows simple message and action button on the bottom or top of the screen with multi kinds of animation, which is written in Swift3 and inspired by Snackbar in Android. It also support showing custom view, icon image or multi action button. Snitch - A handy library to access useful information about your application from the Home Screen
Snitch - A handy library to access useful information about your application from the Home Screen

Snitch Access your app's useful information from Home Screen Table of Contents I

Quick hack to hide the full screen microphone dot on macOS 12.

undot Quick hack to hide the full screen microphone dot on macOS 12. Usage To build: git clone https://github.com/s4y/undot cd undot make To run: whil

A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.

Puffery An iOS App written in SwiftUI to send push notifications fueled by Siri Shortcuts. You can follow other's channels and directly receive update

⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes
⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes

This package lets you add support for user-customizable global keyboard shortcuts to your macOS app in minutes. It's fully sandbox and Mac App Store c

How to add Keyboard Shortcuts to any SwiftUI App with UIKeyCommand
How to add Keyboard Shortcuts to any SwiftUI App with UIKeyCommand

SwiftUI-Keyboard-Demo This tiny project was built to show how simple it is to add keyboard shortcuts (with UIKeyCommand) to any SwiftUI app. After imp

A menu bar app to change input source swiftly using shortcuts on macOS Big Sur or later.

Source Switcher A menu bar app to change input sources swiftly using shortcuts on macOS Big Sur and later. View screenshots Introduction This app uses

Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).
Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).

MCSwipeTableViewCell An effort to show how one would implement a UITableViewCell like the one we can see in the very well executed Mailbox iOS app. Pr

SwiftUI Todo app example using a React/Redux monolithic state store with flux like dispatch/reduce actions
SwiftUI Todo app example using a React/Redux monolithic state store with flux like dispatch/reduce actions

SwiftUI-Todo-Redux SwiftUI Todo Redux app example using a React/Redux monolithic state store with flux like dispatch/reduce actions Background SwiftUI

Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Login-screen-UI - A simple iOS login screen written in Swift 5

This project has been updated to Swift 5 and Xcode 11.2 About This is a simple i

PeekView supports peek, pop and preview actions for iOS devices without 3D Touch capibility
PeekView supports peek, pop and preview actions for iOS devices without 3D Touch capibility

PeekView When implementing peek, pop and preview actions with 3D Touch, you may want to support such features for users accessing your app from older

This repo shows how to setup and use GitHub Actions as a CI for Swift Packages
This repo shows how to setup and use GitHub Actions as a CI for Swift Packages

GACalc This repo shows how to setup and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib List of the all available envi

This repo shows how to set up and use GitHub Actions as a CI for Swift Packages
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)

Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)

A Shortcuts-like and highly customizable SFSymbol picker written in Swift.
A Shortcuts-like and highly customizable SFSymbol picker written in Swift.

SFTintedIconPicker SFTintedIconPicker is a Shortcuts-like and highly customizable SFSymbol picker written in Swift. Features Native Appearance Search

SwiftUI library for a walkthrough or onboarding flow with tap actions
SwiftUI library for a walkthrough or onboarding flow with tap actions

Concentric Onboarding iOS library for a walkthrough or onboarding flow with tap actions written with SwiftUI We are a development agency building phen

3D Touch shortcuts in the Simulator
3D Touch shortcuts in the Simulator

SBShortcutMenuSimulator SBShortcutMenuSimulator is a tweak for the iPhone Simulator that allows you to simulate the new UIApplicationShortcutItem API

Easy to use UITableViewCell implementing swiping to trigger actions.
Easy to use UITableViewCell implementing swiping to trigger actions.

SwipyCell Swipeable UITableViewCell inspired by the popular Mailbox App, implemented in Swift. Preview Exit Mode The .exit mode is the original behavi

Comments
  • Installation

    Installation

    Hello Ricardo,

    Thanks for this module . I was looking forward an easier solution of implementing Quick Actions with my app. However, I ran into some installation issues. Module is installed correctly and recognised with "import" statement at the beginning of my AppDelegate, but then there are some problems:

    Use of undeclared type 'ShortcutType' Cannot specialize non-generic type 'module<QuickActions>'

    Truth be told I'm just following the steps you outlined in the readme file. At this point I'm just guessing which part goes where in my app. Could you please provide and example application for everyone to use as kickstart ?

    opened by staticdreams 8
  • Somehow not working to me. Anyone works?

    Somehow not working to me. Anyone works?

    I ran into one problem and couldn't figure it out what happened. I followed the instructions in the README and also checked the example code, however in performActionForShortcutItem function

    func application(application: UIApplication, performActionForShortcutItem shortcutItem:     UIApplicationShortcutItem, completionHandler: Bool -> Void) {
            guard let quickActions = quickActions else { return completionHandler(false) }
            guard let rootViewController = window?.rootViewController else { return completionHandler(false) }
            completionHandler(quickActions.handle(rootViewController, shortcutItem: shortcutItem))
    }
    

    This line always return false

    quickActions.handle(rootViewController, shortcutItem: shortcutItem)
    

    I don't know if it is because I set something wrong or it is because of the library.

    opened by Tim77277 4
  • Manual Installation

    Manual Installation

    CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

    It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

    opened by lfarah 0
  • Implement custom icon

    Implement custom icon

    I'm currently implementing QuickActions with your framework. I want to set custom icons for the quick actions but I don't really know how exactly. In your source there's the following line:

    if self == .custom {
                NSException(name: NSExceptionName(rawValue: "Invalid option"), reason: "`Custom` type need to be used with `toApplicationShortcutIcon:imageName`", userInfo: nil).raise()
                return nil
            }
    

    To build the shortcuts my code looks like in your example:

    let shortcuts = [
                Shortcut(
                    type: AppShortcut.createExpense,
                    title: NSLocalizedString("CreateExpenseTitle", comment: ""),
                    subtitle: NSLocalizedString("CreateExpenseSubTitle", comment: ""),
                    icon: .add
                )
            ]
    
    

    There's this function:

    func toApplicationShortcutIcon(_ imageName: String) -> UIApplicationShortcutIcon?

    But I don't really know how to call this function or is there another way? Can someone give me an advice how to implement a custom icon?

    opened by Yetispapa 4
Releases(6.1.0)
Owner
Ricardo Pereira
Passionate about #iOS, #latteart and #personalfinance
Ricardo Pereira
JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop interactions on devices that do not natively support this kind of interaction.

JustPeek Warning: This library is not supported anymore by Just Eat. JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop in

Just Eat 68 Apr 4, 2021
The app provides additional actions for the Shortcuts app on macOS and iOS.

Actions Supercharge your shortcuts The app provides additional actions for the Shortcuts app on macOS and iOS. Submit action idea (Submit an issue bef

Sindre Sorhus 1.2k Dec 29, 2022
IconChanger - an app that can change you app's icon. It simplifies your icon changing process

IconChanger IconChanger is an app that can change you app's icon. It simplifies your icon changing process. How to use Go to github release Download t

Underthestars-zhy 561 Jan 5, 2023
This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app.

?? X-BundleIcon This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app. xbi com.apple.Safari 16 /

Rui Aureliano 3 Sep 1, 2022
Icons fonts for iOS (Font Awesome 5, Iconic, Ionicon, Octicon, Themify, MapIcon, MaterialIcon, Foundation 3, Elegant Icon, Captain Icon)

Installation SPM Not yet supported. Please use Cocoapods or Carthage Carthage github "0x73/SwiftIconFont" Cocoapods CocoaPods is a dependency manager

sedat çiftçi 1.1k Dec 14, 2022
Home-assistant-swift-sdk - Used to integrate the Home Assistant APIs with your Swift-based apps.

home-assistant-swift-sdk This open-source library allows you to interact with a Home Assistant instance in your Swift-based (e.g., iOS, macOS, etc.) a

Alexander Golden 0 Dec 31, 2021
Currency Converter - Free and Quick Converter calculates money quick and easy way to see live foreign exchange rates.

Currency Converter - Free and Quick Converter calculates money quick and easy way to see live foreign exchange rates. This app is available in the App

Tirupati Balan 212 Dec 30, 2022
This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application just to practice AutoLayout concepts.

Calculator Layout This "Calculator" application is a simple one screen design of calculator screen i have made this single screen design application j

Chetan Parate 1 Oct 29, 2021
This is an open source app made to help home brewers brew their coffee by calculating the grams of water needed, and run a timer all in the same screen.

Ratios This is an open source app made to help home brewers brew their coffee by calculating the grams of water needed, and run a timer all in the sam

John Peden 64 Jan 1, 2023
SwiftUI mirroring of Instagram app Home screen

Instasoup Is a quick code excercise, where I wanted to do fast prototaping of the Instagram like home view screen in #SwiftUI Check the source code an

Robert Herdzik 11 Feb 27, 2022