Giter Site home page Giter Site logo

homescreenshortcut's Introduction

HomeScreenShortcut

Expose commonly used functionality with static or dynamic 3D Touch Home Screen quick actions.

On the Home screen of a device running iOS 13 or later, apps can display Home Screen quick actions when users touch and hold the app icon (on a 3D Touch device, users press briefly on the icon)

Preview

Where to get SF Symbols

Apple Developer website: https://developer.apple.com/sf-symbols

How to use

1 . Export > choose destination folder for exported templated Export

2 . Copy files that were exported into your project’s assets Copy

Set static quick actions

Use these icons as values for the UIApplicationShortcutItemIconFile field inside the app icon section of the Info.plist(static quick actions) 

Info_plist

UIApplicationShortcutItemType (required):

A unique string that identifies the Quick Action. For example: com.mediumproject.helloWorld.

UIApplicationShortcutItemTitle (required):

The Quick Action title displayed to the user.

UIApplicationShortcutItemSubtitle (optional):

 The Quick Action’s subtitle.

UIApplicationShortcutItemIconType (optional):

Here you can set a predefined icon made by Apple.

UIApplicationShortcutItemIconFile (optional):

Use to set a custom icon.

UIApplicationShortcutItemUserInfo (optional):

A dictionary to save data.

Set dynamic quick actions

Add the following method in the SceneDelegate.swift file

    func sceneWillResignActive(_ scene: UIScene) {
        let application = UIApplication.shared
        application.shortcutItems = [
            UIApplicationShortcutItem(type: "trash", localizedTitle: "Trash", localizedSubtitle: nil, icon: UIApplicationShortcutIcon(systemImageName: "trash.slash.circle"))]
        
    }

Implementation

Add the following method in the SceneDelegate.swift file

    func windowScene(_ windowScene: UIWindowScene,
                     performActionFor shortcutItem: UIApplicationShortcutItem,
                     completionHandler: @escaping (Bool) -> Void) {
        
        switch shortcutItem.type {
        case "send", "trash":
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
                self.window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
                let alert = UIAlertController(title: "Hey", message: "Your quick action works!", preferredStyle: .alert)
                let action = UIAlertAction(title: "OK", style: .default, handler: nil)
                alert.addAction(action)
                self.window?.rootViewController?.present(alert, animated: true, completion: nil)
            }
        default: break
        }
    }

homescreenshortcut's People

Contributors

japanesedesu avatar yamamotodesu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.