Announcements
From September 28th, Community private messages will no longer be available. If you have any private messages you'd like to keep, please save or copy them using these steps before this date. Thank you.

Help Wizard

Step 1

NEXT STEP

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
2 Replies

I am having the exact same issue

I'm also having the same problem. Is it simply not an option to use react-native with the SDK's?

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random