SHLibrary.default.items always return empty list

I want use SHLibrary.default.items to show the music i recognized by Shazam. but SHLibrary.default.items always return empty list.

I did an experiment and I called SHLibrary.default.items as soon as I entered on a page and it returned an empty list, but after use SHManagedSession to identify songs and then call SHLibrary.default.items it returned the result I wanted. Below is the test code

private func bindEvent() {
        
        // call when View was create the  items return empty
        if #available(iOS 17, *) {
            let items = SHLibrary.default.items
            print("-------->>>>>>>>\(items)")
        }
       
        self.addToMediaLibray.onTap { [weak self] in
            guard let `self` = self, let result = self.result, let appleMusicID = result.appleMusicID else { return }
            if #available(iOS 17, *) {
                // call when music was recognized the item is not empty.
                let items = SHLibrary.default.items
                print("1111-------->>>>>>>>\(items)")
            }
        }
    }

The attach file is the part of result log My iOS Verion is iOS 17 (21A5326a) XCode Version is 15.0 beta 8 (15A5229m)

Replies

Can you post the full implementation of the parent class/struct of bindEvent() and details of where the function is called?

  • bindEvent is call when the view is init:

    class ShazamResultCard: UIView { override init(frame: CGRect) { super.init(frame: frame) setUpSubViews() layoutUI() bindEvent() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setUpSubViews() { //........ } private func layoutUI() { //........ } private func bindEvent() { //........ } }
Add a Comment