小编Iam*_*yne的帖子

MPRemoteCommandCenter在swift 4中出错

我正在尝试设置我的应用程序以使用MPRemoteCommandCenter.我从文档编程指南中得到了这个例子.我导入AVFoundation甚至尝试导入AVKIT,我收到错误使用未解析的标识符'MPRemoteCommandCenter'.当我创建MPRemoteCommandCenter.shared()的实例时.任何帮助,将不胜感激.

func setupRemoteTransportControls() {

    // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()   Error //**Use of unresolved identifier 'MPRemoteCommandCenter'**

    // Add handler for Play Command
    commandCenter.playCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 0.0 {
            self.audioPlayer.play()
            return .success
        }
        return .commandFailed
    }

    // Add handler for Pause Command
    commandCenter.pauseCommand.addTarget { [unowned self] event in
        if self.audioPlayer.rate == 1.0 {
            self.audioPlayer.pause()
            return .success
        }
        return .commandFailed
    }
}
Run Code Online (Sandbox Code Playgroud)

avfoundation swift mpremotecommandcenter

6
推荐指数
1
解决办法
1138
查看次数

AVAudio会话中断

尝试处理项目中的音频中断。

该代码曾经在Swift 4中运行。

NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: NSNotification.Name.AVAudioSessionInterruption, object: nil)
Run Code Online (Sandbox Code Playgroud)

自从更新到Swift 4.2之后,它给了我建议更改为

NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: Notification.Name.AVAudioSession.interruptionNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)

更改为建议的修复程序后,我得到了错误: 类型'Notification.Name'(aka'NSNotification.Name')没有成员'AVAudioSession'

任何帮助,将不胜感激。

使用的文件:

func setupNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)
Run Code Online (Sandbox Code Playgroud)

}

但是该文档并未针对Swift 4.2进行更新。

nsnotifications avaudioplayer avaudiosession swift swift4

4
推荐指数
1
解决办法
577
查看次数

Firebase 下载进度观察器错误 Swift 3

尝试显示 firebase 下载进度,出现错误

“FIRStorageRef 类型的值没有成员观察”。

这是我从 firebase 文档中获得并尝试使用的代码。

    storage = FIRStorage.storage()

    let storageRef = storage.reference().child("Audio").child(successFileName)
    self.titleLabel.text =  self.successTitlename

    SwiftSpinner.show("Loading...")

    storageRef.downloadURL { url, error in
        if error != nil {

            SwiftSpinner.show("Couldn't load Audio...Tap to dismiss").addTapHandler({
                SwiftSpinner.hide()
            })
       **Getting error here** 
            storageRef.observe(.progress) { snapshot in
 // Download reported progress
    let percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount)
                    / Double(snapshot.progress!.totalUnitCount)
            }


}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,提前致谢。

ios firebase firebase-realtime-database swift3 firebase-storage

1
推荐指数
1
解决办法
1560
查看次数

从文档目录而不是文件路径获取图像Swift 3

这就是我保存图像的方式

    let format = DateFormatter()
    format.dateFormat="MMMM-dd-yyyy-ss"
    let currentFileName = "\(format.string(from: Date())).img"
    print(currentFileName)

    // Save Images
    let fileMgr = FileManager.default
    let dirPath = fileMgr.urls(for: .documentDirectory, in: .userDomainMask)[0]
    let imageFileUrl = dirPath.appendingPathComponent(currentFileName)



        do {

            try UIImagePNGRepresentation(returnedImages)!.write(to: imageFileUrl)

            print("Image Added Successfully")

    } catch {

        print(error)

        }
Run Code Online (Sandbox Code Playgroud)

下面是我用来检索图像的代码,但是我正在获取URL而不是图像文件来填充tableview。任何帮助,将不胜感激

   let fileManager = FileManager.default
   let imageUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask) [0].appendingPathComponent("img")

   print("Your Images:\(imageUrl)")
Run Code Online (Sandbox Code Playgroud)

nsdocumentdirectory swift swift3 xcode8

0
推荐指数
1
解决办法
3289
查看次数

如何格式化“5 分钟”、“1 小时”、“昨天”、“1 周前”等日期?

我正在尝试获得类似于 facebook 发布日期/时间的内容。像 1 分钟、1 小时、昨天、一周前等。

这是我用来获取这种格式的函数:( Oct-22 17:28 PM)

func convertTime(serverTime: Double)  -> String {
    let serverTime = serverTime
    let date = Date(timeIntervalSince1970: serverTime)
    let dateFomatter = DateFormatter()
    dateFomatter.dateFormat = "MMM-dd HH:mm a"
    let strDate = dateFomatter.string(from: date)
    print("This is the post's date: \(strDate)")

    return strDate
}
Run Code Online (Sandbox Code Playgroud)

nsdate xcode6 swift3

0
推荐指数
1
解决办法
247
查看次数