Davis Hoang
Davis Hoang

Reputation: 87

iTunesLibrary get all music

I'm new on swift 4. I'm trying to develop a simple mac program to get all music songs from iTunesLibrary. I did sign my code and import iTunesLibrary.framework to the project. But I get an error about iTlib XPC connection error:

2018-05-29 19:51:16.277312+0700 KODE[2325:47137] ITLib received XPC_ERROR_CONNECTION_INTERRUPTED connection error (can be ignored). 2018-05-29 19:51:16.277410+0700 KODE[2325:47137] ITLib xpc error: Connection interrupted 2018-05-29 19:51:16.277441+0700 KODE[2325:47072] Assertion failure: status == noErr (100005)

Here is my code

override func viewDidLoad() {
    super.viewDidLoad()

    let library: ITLibrary

    do {
        library = try ITLibrary(apiVersion: "1.0")
    } catch {
        print("Error occured!")
        return
    }

    let tracks = library.allMediaItems

    for track in tracks {
        print(track.album.title!)
    }

    // Do any additional setup after loading the view.
}

Upvotes: 1

Views: 334

Answers (1)

Nuzhdin Vladimir
Nuzhdin Vladimir

Reputation: 1822

If you have a sandboxed app, go to Capabilites/"App Sandbox"/"File Access"/"Music Folder". Change "None" to "Read Only". It helped me. Also app must be properly signed.

Upvotes: 1

Related Questions