InputMethodKit Sample App with macOS11, Xcode13, Swift5.5 in 2021.

Overview

What is this?

This is a sample implementation of IMKit App with Swift/SwiftUI.

Working Environment

  • macOS 11.5
  • Swift 5.5
  • Xcode13 (beta)

Procedure to make project

  • Create new project. Bundle Identifier must contain .inputmethod. part in the String.

  • Run.

  • Remove IMKitSampleApp.swift, ContentView.swift

  • Add Swift files AppDelegate.swift and IMKitSampleInputController.swift.

    // AppDelegate.swift
    import Cocoa
    import InputMethodKit
    
    // necessary to launch this app
    class NSManualApplication: NSApplication {
        private let appDelegate = AppDelegate()
    
        override init() {
            super.init()
            self.delegate = appDelegate
        }
    
        required init?(coder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
    }
    
    @main
    class AppDelegate: NSObject, NSApplicationDelegate {
        var server = IMKServer()
        var candidatesWindow = IMKCandidates()
    
        func applicationDidFinishLaunching(_ notification: Notification) {
            // Insert code here to initialize your application
            server = IMKServer(name: Bundle.main.infoDictionary?["InputMethodConnectionName"] as? String, bundleIdentifier: Bundle.main.bundleIdentifier)
            candidatesWindow = IMKCandidates(server: server, panelType: kIMKSingleRowSteppingCandidatePanel, styleType: kIMKMain)
            NSLog("tried connection")
        }
    
        func applicationWillTerminate(_ notification: Notification) {
            // Insert code here to tear down your application
        }
    }
    // IMKitSampleInputController.swift
    import Cocoa
    import InputMethodKit
    
    @objc(IMKitSampleInputController)
    class IMKitSampleInputController: IMKInputController {
        override func inputText(_ string: String!, client sender: Any!) -> Bool {
            NSLog(string)
            // get client to insert
            guard let client = sender as? IMKTextInput else {
                return false
            }
            client.insertText(string+string, replacementRange: NSRange(location: NSNotFound, length: NSNotFound))
            return true
        }
    }
  • Add icon file main.tiff.

  • Modify Info.plist

    key: NSPrincipalClass  type: _  value: $(PRODUCT_MODULE_NAME).NSManualApplication
    key: InputMethodConnectionName  type: String  value: $(PRODUCT_BUNDLE_IDENTIFIER)_Connection
    key: InputMethodServerControllerClass  type: String  value: $(PRODUCT_MODULE_NAME).IMKitSampleInputController
    key: Application is background only  type: Boolean  value: YES
    key: tsInputMethodCharacterRepertoireKey  type: Array  value: [item0: String = Latn]
    key: tsInputMethodIconFileKey  type: String  value: main.tiff
    
  • Add entitlements

    • Go Signing & Capabilities+CapabilityApp Sandbox

    • Go IMKitSample.entitlements, add

      key: com.apple.security.temporary-exception.mach-register.global-name
      type: String
      value: $(PRODUCT_BUNDLE_IDENTIFIER)_Connection
      
  • Do sudo chmod -R 777 /Library/Input\ Methods on terminal.

  • Modify build settings.

    • Go Build LocationsBuild Products Path of debug → value ``/Library/Input Methods`
    • Go +Add User-Defined Setting → Set key CONFIGURATION_BUILD_DIR, value /Library/Input Methods.
    • !!! DO NOT edit thinklessly, this setting is really fragile.
  • Try Run.

Trouble Shooting

I'm not expert of macOS. Please don't ask too much, I don't know either. It's just my experience.

  • InputMethods says connection **Failed** all though there are no diff!

    • Open 'Activity Monitor' app, search the name of your InputMethods, and kill the process. Then try again.
  • print() doesn't work!

    • Use NSLog().
  • App doesn't run!

    • Check the path of build product file. If it isn't at /Library/Input Methods/..., some thing went wrong.
    • Maybe build setting went wrong. Check the settings. Especially, if CONFIGURATION_BUILD_DIR=""; found, remove the line.
  • Where's my InputMethod!?!?

    • Check English section. You would found it.

Reference

Thanks to authors!!

You might also like...
This is a sample project that supplements the tutorial written over at my blog on 'Building a music recognization app in SwiftUI with ShazamKit'
This is a sample project that supplements the tutorial written over at my blog on 'Building a music recognization app in SwiftUI with ShazamKit'

Shazam-Kit-Tutorial This is a sample project that supplements the tutorial written over at my blog on 'Building a music recognization app in SwiftUI w

A sample iOS app built using the Clean Swift architecture

Main Purpose is to create a simple project for Clean-Swift This project wrote with using Clean-Swift and MVP Design Pattern

Sample app to demonstrate the integration code and working of Dyte SDK for iOS, using Swift
Sample app to demonstrate the integration code and working of Dyte SDK for iOS, using Swift

docs-template by dyte ADD_DESCRIPTION_HERE Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About the Project Built With

A sample app that will display some airport information using MVVM pattern

Simulator.Screen.Recording.-.iPhone.11.-.2021-11-15.at.14.27.41.mp4 AirportDisplayApp A sample app that will display some airport information using MV

 Sample iOS App  - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation
 Sample iOS App - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation

 Sample iOS App - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation, and more

This sample app use the Star Wars public api to show a list of characters

StarWars-MVVM In this sample app, I use the Star Wars public api to show a list of characters from the Star Wars movie series. There are two goals I w

Apple ExtensionFoundation/ExtensionKit sample app
Apple ExtensionFoundation/ExtensionKit sample app

TextTransformer: an ExtensionKit sample app This year's WWDC introduced many new APIs, two of which caught my attention: ExtensionFoundation and Exten

Sample Code for WWDC21

WWDC21 Sample Code Accessibility Create Accessible Experiences for watchOS Creating Accessible Views WWDC21 Challenge: Large Text Challenge WWDC21 Cha

Comments
  • [Bug] Window opens

    [Bug] Window opens

    You should remove SwiftUI App struct, and attach @main to AppDelegate. In order to make it work successfully, you must add custom NSApplication class that launches AppDelegate.

    opened by ensan-hcl 0
  • run succesfully ,but i don't know how to use it.

    run succesfully ,but i don't know how to use it.

    hello ensan

    thanks for your share

    I run the sample on my mac with no issue.

    but I can not find IMKitSample in the input source. so I can not switch to it.

    how can I use the input method in my text editor?

    opened by alancpu 1
Owner
ensan
Swift User. Developer of azooKey.
ensan
🎉 WWDC 2021 Swift Student Challenge Winner 🎉 Dance Party allows users to record choreography and play against other users to try and match the key poses!

?? Dance Party ?? ?? WWDC 2021 Swift Student Challenge Winner ?? Installation Steps (Works on iPad Only) Clone or Download Unzip the .playgroundbook.z

Alan Yan 7 Oct 17, 2022
This is example project for my presentation in iOSDC JAPAN 2021

Swift PM Project Example This is example project for my presentation in iOSDC JAPAN 2021. Package.swift based project management Multi Modules Multi P

Daiki Matsudate 28 Nov 11, 2022
The concept won first place in the Design Concept Award contest Season 1 in 2021.

TallyCounter Developed by Vladyslav Fil as part of the You are launched "Design Concept Award" contest Season #1. Tally Counter Micro-Interaction demo

You are launched 3 Dec 17, 2022
The concept took third place in the Design Concept Award contest Season 1 in 2021.

SpringAnimation Developed by Yurii Sameliuk as part of the You are launched "Design Concept Award" contest Season #1. SpringAnimation demo. Inspired b

You are launched 5 Jul 10, 2022
The concept won first place in the Design Concept Award contest Season 1 in 2021.

TallyCounter Developed by Vladyslav Fil as part of the You are launched "Design Concept Award" contest Season #1. Tally Counter Micro-Interaction demo

You are launched 3 Dec 17, 2022
My winning contribution to Apple's Swift Student Challenge 2021

SynthApp My winning contribution to Apple's Swift Student Challenge 2021 This repository contains an Xcode project and the final Swift Playgrounds fil

Sl4sh! 1 Dec 4, 2021
The concept won first place in the Design Concept Award contest Season 2 in December 2021.

SwiftUI-ChristmasGift Developed by Alex Kryvodub as part of the You are launched "Design Concept Award" contest Season #2. ChristmasGift demo. alex.mp

You are launched 5 Jan 12, 2022
The concept took second place in the Design Concept Award contest Season 2 December 2021.

SwiftUI-UrlaunchedMerryChristmasCard Developed by Yurii Sameliuk as part of the You are launched "Design Concept Award" contest Season #2. MerryChrist

You are launched 6 Jun 17, 2022
The concept took third place in the Design Concept Award contest Season 2 in December 2021.

SwiftUI-UrlaunchedLaunchScreen Developed by Vladyslav Fil as part of the You are launched "Design Concept Award" contest Season #2. Animated Launch Sc

You are launched 5 Jan 3, 2023
Sample app to demonstrate using Firebase features

Photoram Sample app to demonstrate using Firebase features Uses: Firebase authentification for login and registrations Firebase storage to keep image

Anna Zharkova 3 Jun 4, 2021