Skip to content

Commit dbb9f09

Browse files
committed
fix: call aAuthorizeAndPlayURI on main thread which internally calls UIAppliation.openURL
1 parent b380700 commit dbb9f09

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ios/Classes/SwiftSpotifySdkPlugin.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public class SwiftSpotifySdkPlugin: NSObject, FlutterPlugin {
337337
}
338338
}
339339

340-
private func connectToSpotify(clientId: String, redirectURL: String, accessToken: String? = nil, spotifyUri: String = "", asRadio: Bool?, additionalScopes: String? = nil) throws {
340+
private func connectToSpotify(clientId: String, redirectURL: String, accessToken: String? = nil, spotifyUri: String = "", asRadio: Bool?, additionalScopes: String? = nil) throws {
341341
func configureAppRemote(clientID: String, redirectURL: String, accessToken: String? = nil) throws {
342342
guard let redirectURL = URL(string: redirectURL) else {
343343
throw SpotifyError.redirectURLInvalid
@@ -366,13 +366,13 @@ public class SwiftSpotifySdkPlugin: NSObject, FlutterPlugin {
366366
if accessToken != nil {
367367
appRemote?.connect()
368368
} else {
369-
let appRemote = self.appRemote
370-
Task {
371-
// Note: A blank string will play the user's last song or pick a random one.
372-
if await appRemote?.authorizeAndPlayURI(spotifyUri, asRadio: asRadio ?? false, additionalScopes: scopes) == false {
373-
throw SpotifyError.spotifyNotInstalledError
369+
// Note: A blank string will play the user's last song or pick a random one.
370+
self.appRemote?.authorizeAndPlayURI(spotifyUri, asRadio: asRadio ?? false, additionalScopes: scopes) { success in
371+
if (!success) {
372+
self.connectionStatusHandler?.connectionResult?(FlutterError(code: "spotifyNotInstalled", message: "Spotify app is not installed", details: nil))
374373
}
375374
}
375+
}
376376
}
377377
}
378378

0 commit comments

Comments
 (0)