Festify / cordova-spotify-oauth

🔐 Easy Spotify authentication for Cordova / PhoneGap apps
MIT License
16 stars 18 forks source link

Ios - SpotifyOAuthPlugin.swift - observer not seems to be working #37

Open rijink7 opened 3 years ago

rijink7 commented 3 years ago

the plugin works well up to auth process after auth the SFSafariViewController stays in the spotify redirect page does not dismiss the SFSafariViewController.

    var observer: NSObjectProtocol?
    observer = NotificationCenter.default.addObserver(
        forName: NSNotification.Name.CDVPluginHandleOpenURL,
        object: nil,
        queue: nil
    ) { note in
        let url = note.object as! URL
        guard url.absoluteString.contains("code") else { return }

        svc.presentingViewController!.dismiss(animated: true, completion: nil)
        NotificationCenter.default.removeObserver(observer!)
        self.currentNsObserver = nil
        self.currentCommand = nil

        let res = CDVPluginResult(
            status: CDVCommandStatus_OK,
            messageAs: [
                "code": url["code"]
            ]
        )
        self.commandDelegate.send(res, callbackId: command.callbackId)
    }