Search code examples
iosswiftuiimessageimessage-extension

Create a Standalone iMessage app without Storyboard


I wish to create a Standalone iMessage app without using a storyboard. No app icon would appear on the Home Screen.

First I create a simple ViewController:

@objc (MessagesViewController)
class MessagesViewController: MSMessagesAppViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let child = UIHostingController(rootView: SwiftUIView())
        child.view.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(child.view)
        
        NSLayoutConstraint.activate([
            child.view.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0),
            child.view.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0),
            child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0),
            child.view.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0)
        ])
    }
}

Then a simple View:

struct SwiftUIView: View {
    var body: some View {
        Text("Hello, Earth!")
    }
}

My Info.plist references the view controller class:

<key>NSExtension</key>
<dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.message-payload-provider</string>
    <key>NSExtensionPrincipalClass</key>
    <string>$(PRODUCT_MODULE_NAME).MessagesViewController</string>
</dict>

This is my Project navigator:

Project navigator

The app builds, and launches on the simulator (or device), but no app appears in Messages. What might I be doing wrong?


Solution

  • It appears my problem might be a bug in the latest version of Xcode (15.x), in the iMessage App template. See this post from @noahbkim: