Swift - Сбой авторизации API Spotify - PullRequest
0 голосов
/ 11 января 2020

Я пытаюсь получить токен доступа Spotify с помощью фреймворка 'SpotifyLogin' (построенного с Spotify API) - https://github.com/spotify/SpotifyLogin.

Я добавил 'SpotifyLoginButton' (прилагается) в рамках) к мнению. После выбора платформа успешно открывает Spotify, представляет страницу авторизации и перенаправляет обратно в приложение.

Однако активный сеанс не создается - поэтому уведомление об успешном входе в систему не отправляется.

Я начинаю думать, что это проблема с фреймворком, но хотел опубликовать здесь, если мой код ошибочен.

Вот код:

class LoginViewController: UIViewController {

    @IBOutlet weak var BlueBackView: UIView!
    @IBOutlet weak var LogoImageView: UIImageView!
    @IBOutlet weak  var StartedLabel: UILabel!

    override func viewDidAppear(_ animated: Bool) {

        super.viewDidLoad()

        // Creates button and adds constraints
        let mySpotifyLoginButton = self.CreateLoginButton()

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(responseToSuccessfulLogin),
                                               name: .SpotifyLoginSuccessful,
                                               object: nil)

        self.view.addSubview(mySpotifyLoginButton)
    }

    @objc func responseToSuccessfulLogin() {
        print("logged in")
        self.dismiss(animated: true, completion: nil)
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }

Попытки решения:

Я написал «голое» приложение с одной кнопкой на V C, и у него та же проблема. Я также получаю это сообщение об ошибке, но я думаю, что это может быть iOS 13 ошибка:

2020-01-11 01:32:27.816836+0000 testingspot[8406:2834566] Can't end
 BackgroundTask: no background task exists with identifier 1 (0x1), or it
 may have already been ended. Break in
UIApplicationEndBackgroundTaskError() to debug.

Любая помощь по этому очень расстраивающему вопросу будет высоко ценится.

Спасибо в заранее!

PS Буду признателен за любую помощь, даже если это проблема с рамками. Я поднял вопрос о Github, но хранилище, кажется, не очень активно, и поэтому проблема, скорее всего, там не будет решена.

ДОПОЛНИТЕЛЬНЫЕ ДАННЫЕ

//App Delegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        //Spotify
        let SPOTIFY_CLIENT_ID = "id_removed_for_stack_overflow"
        let SPOTIFY_CLIENT_SECRET = "secret_removed_for_stack_overflow"

        let callbackURI = URL(string: "removeddforstackoverflow://returnafterlogin")!
        SpotifyLogin.shared.configure(clientID: SPOTIFY_CLIENT_ID, clientSecret: SPOTIFY_CLIENT_SECRET, redirectURL: callbackURI)

        return true
    }

    //deprecated?
    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        let handled = SpotifyLogin.shared.applicationOpenURL(url) { _ in }
        return handled
    }

    // MARK: UISceneSession Lifecycle

    //lock all view controllers to portrait
    let PORTRAIT_LOCK = UIInterfaceOrientationMask.portrait

    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return self.PORTRAIT_LOCK
    }

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }


}

Соответствующие части Info.plist

<plist version="1.0">
<dict>
    <array>
        <dict>
            <key></key>
            <string></string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>com.personal.slidr</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>removedforstackoverflow</string>
            </array>
        </dict>
        <dict/>
    </array>

    <key>LSApplicationCategoryType</key>
    <string></string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>spotify-action</string>
    </array>

</dict>
</plist>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...