Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

AppRemote not connecting

AppRemote not connecting

Plan

Premium

 

Device

iPhone 12 Max Pro

 

Operating System

iOS

 

My Question or Issue

Hi,

 

i am new to Swift an iOS development, so maybe this is an easy question, but i am really struggling with it. I am trying to connect to Spotify and play a song via appRemote. But when I try to connect my appRemote it is canceled with the following issue:

 

AppRemote: Connecting...

nw_socket_handle_socket_event [C2.1.1:1] Socket SO_ERROR [61: Connection refused]

nw_endpoint_flow_failed_with_error [C2.1.1 ::1.9095 in_progress socket-flow (satisfied (Path is satisfied), viable, interface: lo0)] already failing, returning

 

This is the Code from my ViewController:

 

class ViewController: UIViewController, UIApplicationDelegate, SPTSessionManagerDelegate, SPTAppRemoteDelegate, SPTAppRemotePlayerStateDelegate {

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view.

    }

    let SpotifyClientID = "..."

    let SpotifyRedirectURL = URL(string: "test://callback")!

    lazy var configuration = SPTConfiguration(

        clientID: SpotifyClientID,

        redirectURL: SpotifyRedirectURL

    )

    

    lazy var sessionManager: SPTSessionManager = {

        print("sessionManager")

        let manager = SPTSessionManager(configuration: configuration, delegate: self)

        return manager

    }()




    lazy var appRemote: SPTAppRemote = {

        print("appRemote")

        let appRemote = SPTAppRemote(configuration: configuration, logLevel: .debug)

        appRemote.delegate = self

        return appRemote

    }()


    @IBAction func connectToSpotify(_ sender: UIButton) {

        let requestedScopes: SPTScope = [.appRemoteControl]

        self.sessionManager.initiateSession(with: requestedScopes, options: .default, campaign: nil)

    }

    func sessionManager(manager: SPTSessionManager, didInitiate session: SPTSession) {

        print("sessionManager didInitiate")

        self.appRemote.connectionParameters.accessToken = session.accessToken

        print("AccessToken: \(session.accessToken)")

        self.appRemote.connect()

    }

    

    func sessionManager(manager: SPTSessionManager, didFailWith error: Error) {

        print("sessionManager didFailWith")

        print(error)

    }

    
    func sessionManager(manager: SPTSessionManager, didRenew session: SPTSession) {

        print("sessionManager didRenew")

        print(session)

    }

    

    func appRemoteDidEstablishConnection(_ appRemote: SPTAppRemote) {

        print("connected")

        self.appRemote.playerAPI?.play("spotify:track:003vvx7Niy0yvhvHt4a68B", callback: { (result, error) in

           if let error = error {
                print(error.localizedDescription)
            }
        })

    }

...
}

 The code mainly was copied from the official example linked in the Spotify documentation but I tried to move the SessionManager from the AppDelegate to the ViewController. But when I do that I get the mentioned error. Can somebody help me? 🙂

Reply
0 Replies

Suggested posts