rryam / MusadoraKit

The ultimate companion to MusicKit.
http://exploringmusickit.com
MIT License
340 stars 22 forks source link

MusicKit with SPM #46

Closed jayadamsmorgan closed 1 month ago

jayadamsmorgan commented 1 month ago

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 and MusadoraKit

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>

The problem is whenever I run the built executable from the command line it crashes on MusicAuthorization.request() If I run it from Xcode the app runs fine. But if I also try run Xcode built executable from the command line it also fails. It's kind of frustrating, not really know when to look. Any advice?

To Reproduce Steps to reproduce the behavior:

  1. Build the project with swift build
  2. Run the executable from command line

Desktop (please complete the following information):

Additional context Also tried the release version and running with sudo

jayadamsmorgan commented 1 month ago

Solved by manually adding terminals and the app itself in System Settings > Privacy & Security > Media & Apple Music