Create a widget template for iOS14 with Intent Configuration.

Create a widget template added in iOS14 with Intent Configuration. (Those who can see the "Edit Widget" menu) Use Xcode auto-generation whenever possible. Since it is a template, it has no function, but I hope it will be the basis for mass production of widgets.

Creating an app

I think most of the apps are still made with UIKit, so I chose ʻUIKit App Delegate. The name is LeaderCard` assuming a credit card application. : relaxed: image.png

Creating a Widget Extension

Press + here. image.png

Select Widget Extension and press Next. image.png

ʻCheck Include Configuration Intent. (← important here!) If you do not check it, it will be Static Configuration. The Widget name is LeaderCardWidget`. image.png

Creating an Intent Handler

Press + here. image.png

Select Intents Extension and press Next. image.png

ʻDo not check Include UI Extension. (← important here!) Select None for Starting Point. (← important here!) The Intent Handler name is LeaderCardIntent`. image.png

setting of intent definition

Open the LeaderCardWidget.intentdefinision generated in the LeaderCardWidget folder. image.png Press + at the bottom to select New Type. image.png Set Card to the type name. You don't have to touch the contents of Card. image.png Parameters Set as shown in the figure below. image.png

Parameter Parameter is set to card in lowercase. (← important here!) image.png This is because it is the property name of the automatically generated class ConfigurationIntent.

Display Name The character string specified here is displayed in the location shown in the figure below.

Type Select Card.

Configurable To check.

Dynamic Options To check.

Prompt Label The character string specified here is displayed in the location shown in the figure below.

Target Membership Check LeaderCardWidgetExtension and LeaderCardIntent. (← important here!) image.png

At least code the Intent Handler

initial state

IntentHandler.swift


class IntentHandler: INExtension {
    
    override func handler(for intent: INIntent) -> Any {
        // This is the default implementation.  If you want different objects to handle different intents,
        // you can override this and return the handler you want for that particular intent.
        
        return self
    }
    
}

Add the ConfigurationIntentHandling protocol. image.png Then you will be asked if you want to add a protocol stub, so press Fix. image.png The provideCardOptionsCollection method is added. image.png

Write completion (nil, nil) in the code part. (Since it is a template, nothing works.)

IntentHandler.swift


class IntentHandler: INExtension {
    func provideCardOptionsCollection(for intent: ConfigurationIntent, with completion: @escaping (INObjectCollection<Card>?, Error?) -> Void) {
        completion(nil, nil)
    }
    
    override func handler(for intent: INIntent) -> Any {
        // This is the default implementation.  If you want different objects to handle different intents,
        // you can override this and return the handler you want for that particular intent.
        
        return self
    }
    
}

Complete

The template should now be complete. When executed, the following screen will be displayed. We will flesh out this and get closer to the desired widget. image.png

GitHub We have created a Template repository here, so please use it if you like. iOS14-Widget-IntentConfiguration-template

Development environment

Recommended Posts

Create a widget template for iOS14 with Intent Configuration.
Create a playground with Xcode 12
Tutorial to create a blog with Rails for beginners Part 1
Tutorial to create a blog with Rails for beginners Part 2
Tutorial to create a blog with Rails for beginners Part 0
A tool to generate Retina images for iOS for use with Xcode
Create a JVM for app distribution with JDK9 modules and jlink
Create exceptions with a fluid interface
Create a Maven project with a command
Create a fluentd server for testing
[Ruby on Rails] Create a pie chart for each column with Chartkick
Create a java web application development environment with docker for mac part2
Notes for using BLE with iOS apps
Create a jar file with the command
Create a simple web application with Dropwizard
Create a simple on-demand batch with Spring Batch
Create a GUI JSON Viewer with Ruby/GTK3
[Rails withdrawal] Create a simple withdrawal function with rails
How to create a Maven repository for 2020
Create a MySQL environment with Docker from 0-> 1
Create a simple bar chart with MPAndroidChart
Create a temporary class with new Object () {}
[rails] How to create a partial template
[Rails 5] Create a new app with Rails [Beginner]
Make a site template easily with Rails
How to create an Excel form using a template file with Spring MVC
Create a website with Spring Boot + Gradle (jdk1.8.x)
How to create a database for H2 Database anywhere
[Memo] Create a CentOS 8 environment easily with Docker
Create a simple search app with Spring Boot
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
[Rails] rails new to create a database with PostgreSQL
Let's create a timed process with Java Timer! !!
A note for those who live with JMockit
How to create pagination for a "kaminari" array
[Java] Create a collection with only one element
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
Create a team chat with Rails Action Cable
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
Create a SandBox account with fastlane spaces ip
Create a tool for name identification in Salesforce
Create related data together with FactoryBot for yourself
Create a multi-key map with the standard library
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
Create a web api server with spring boot
Create a docker environment for Oracle 11g XE
Create a Spring Boot development environment with docker
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]