代码之家  ›  专栏  ›  技术社区  ›  Chris Marshall

如何让iPhone/iPad完全忘记应用程序的媒体授权状态?

  •  2
  • Chris Marshall  · 技术社区  · 7 年前

    交易如下:

    我正在编写一个应用程序,可以播放用户库中的音乐。我正在使用MP授权方法,如下所示:

            if .authorized == MPMediaLibrary.authorizationStatus() {    // Already authorized? Head on in!
                if inDisplayWholeScreenThrobber {
                    self._showLargeLookupThrobber()
                }
                if let songItems: [MPMediaItemCollection] = MPMediaQuery.songs().collections {
                    self._loadSongData(songItems)
                    self._selectSong()
                    self._hideLargeLookupThrobber()
                }
            } else {    // Can I see your ID, sir?
                MPMediaLibrary.requestAuthorization { [unowned self] status in
                    switch status {
                    case.authorized:
                        if inDisplayWholeScreenThrobber {
                            self._showLargeLookupThrobber()
                        }
                        if let songItems: [MPMediaItemCollection] = MPMediaQuery.songs().collections {
                            self._loadSongData(songItems)
                            self._selectSong()
                            self._hideLargeLookupThrobber()
                        }
    
                    default:
                        TheBestClockAppDelegate.reportError(heading: "ERROR_HEADER_MEDIA", text: "ERROR_TEXT_MEDIA_PERMISSION_DENIED")
                    }
                }
            }
    

    等等在播放任何存储的URI之前,我还会检查授权状态,以防用户改变主意。

    一旦我授予(或拒绝)授权,系统就会记住我的应用程序,以后再也不会有人问我了。即使卸载应用程序并重新安装,也只会重新唤醒隐私面板中的开关。

    这给了我两个问题:

    1) 我做得对吗,上面?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Chris Marshall    7 年前

    好啊我想出了一个办法。很烦人,但它很管用。

    如果删除应用程序,然后关闭并重新启动设备,则状态将重置。