This is probably not the place to ask this question, but I'm not sure where else to ask...
I am building a CLI tool which would use MusicKit
Package.swift
:
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Yatoro",
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.1"),
],
targets: [
.executableTarget(
name: "Yatoro",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Logging", package: "swift-log"),
],
linkerSettings: [
.unsafeFlags([
"-Xlinker", "-sectcreate",
"-Xlinker", "__TEXT",
"-Xlinker", "__info_plist",
"-Xlinker", "Sources/Yatoro/Resources/Info.plist",
])
]
),
]
)
Info.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>Yatoro</string>
<key>CFBundleIdentifier</key>
<string>mybundleidentifier.yatoro</string>
<key>NSAppleMusicUsageDescription</key>
<string>This app requires access to Apple Music to play music tracks.</string>
</dict>
</plist>
I have found this solution to include Info.plist into the SwiftPM build with the linker flags.
If I run it from Xcode the CLI app runs fine and I get the authorization prompt. But if I try to run Xcode built executable or the executable built with swift build
from the command line it crashes on MusicAuthotization.request()
.
It's kind of frustrating, not really know when to look. Any advice?