小编lit*_*ium的帖子

AVSpeechSynthesizer在iOS10上不起作用

我的AVSpeechSynthesizer代码不能在设备上运行(iOS 10),但它可以在iOS 9.x上运行,现在它可以在模拟器中运行.

let str = self.audioOutput //just some string here, this string exists, and it's in english
let synth = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: str)
    utterance.rate = AVSpeechUtteranceDefaultSpeechRate
let lang = "en-US"

utterance.voice = AVSpeechSynthesisVoice(language: lang)
synth.speakUtterance(utterance)
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

MobileAssetError:1] Unable to copy asset attributes
Could not get attribute 'LocalURL': Error Domain=MobileAssetError Code=1 "Unable to copy asset attributes"
UserInfo={NSDescription=Unable to copy asset attributes}
0x1741495e0 Copy assets attributes reply: XPC_TYPE_DICTIONARY  <dictionary: 0x1741495e0> { count = 1, transaction: 0, voucher = …
Run Code Online (Sandbox Code Playgroud)

ios avspeechsynthesizer swift

22
推荐指数
3
解决办法
8772
查看次数

iOS 10的语音识别限制

有谁知道iOS 10(每台设备或每个应用程序)的语音识别是否有限制?

speech-recognition ios10 apple-speech

9
推荐指数
2
解决办法
4795
查看次数

AVAudioSession 和 AirPods

我的应用程序似乎无法与 AirPods 配合使用。现在我正在使用此代码进行播放和录制:

\n\n
    let audioSession = AVAudioSession.sharedInstance()\n    do { try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.defaultToSpeaker)\n    }catch {\n        print("audioSession properties weren\'t set because of an error.")\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

defaultToSpeaker如果我改为就够了吗allowBluetooth

\n\n

PS 我知道这是一个相当愚蠢的问题,因为只需更改此行并检查会简单得多,但我现在没有 AirPods,所以我唯一的选择就是上传Testflight 的新构建(我想以最少的迭代来完成此操作)。

\n\n

更新:(相当幼稚的方法 \xe2\x80\x94 但我需要的只是使用蓝牙耳机(如果可用):

\n\n
func selectDevice(audioSession: AVAudioSession) {\n\n    var headphonesExist = false\n    var bluetoothExist = false\n    var speakerExist = false\n\n    let currentRoute = AVAudioSession.sharedInstance().currentRoute\n\n    for output in audioSession.currentRoute.outputs {\n        print(output)\n\n        if output.portType == AVAudioSessionPortHeadphones || output.portType == AVAudioSessionPortHeadsetMic {\n            headphonesExist = true\n        }\n\n …
Run Code Online (Sandbox Code Playgroud)

audio avfoundation ios avaudiosession swift

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

UITapGestureRecognizer无法与Google Maps SDK一起使用

我有一个mapViewController,上面有一些自定义UIView(只有两个带有某些背景的标签)。我想在此UIView上点击后显示新的ViewController。

因此,我的代码(对于其他情况,这是一个可行的解决方案)用于自定义UIView:

 tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "checkGesture:")
        tapGestureRecognizer.numberOfTapsRequired = 1
        self.userInteractionEnabled = true
        self.addGestureRecognizer(tapGestureRecognizer)
Run Code Online (Sandbox Code Playgroud)

func checkGesture(sender: UITapGestureRecognizer) {
    print("it works")
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里是什么问题?

编辑(已解决):因此,我尝试将此自定义UIView放在另一个ViewController上,并且可以正常工作。看来这个问题的主要根源是我的MapViewController中的下一部分代码:

let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
    self.view = mapView
Run Code Online (Sandbox Code Playgroud)

没有最后一行(self.view = mapView),我的自定义UIView可以正常工作(但是我没有任何地图,因此我不得不对此代码稍作更改)。

let mapView = GMSMapView.mapWithFrame(CGRectMake(0, 0, self.view.frame.width, self.view.frame.height), camera:camera)
    self.view.addSubview(mapView)
Run Code Online (Sandbox Code Playgroud)

ios swift

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

ClipsToBounds在单元格中不起作用

我有一个带自定义单元格的UITableView.每个单元格的结构都是这样的:我有contentView,在这个contentView中我有backView(简单的UIView有白色背景和角落半径16.0),在这个backView我有一个带有一些图片的imageView.

我想要的是让这个imageView走投无路(在他的父UIView - backView - 边框内).而且这种方式不起作用.

代码非常简单(来自ImageCell.swift):

    self.backView = UIView()
    self.backView.backgroundColor = UIColor.white
    self.backView.translatesAutoresizingMaskIntoConstraints = false
    self.backView.layer.cornerRadius = 16.0
    self.contentView.addSubview(backView)

    self.picture = UIImageView()
    self.picture.translatesAutoresizingMaskIntoConstraints = false
    self.picture.contentMode = UIViewContentMode.scaleAspectFill
    self.picture.backgroundColor = UIColor.gray
    self.picture.clipsToBounds = true
    self.backView.addSubview(picture)

    let constraintPicTop = NSLayoutConstraint(item: picture, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .topMargin, multiplier: 1.0, constant: -6)
    let constraintPicLeft = NSLayoutConstraint(item: picture, attribute: .left, relatedBy: .equal, toItem: backView, attribute: .leftMargin, multiplier: 1.0, constant: -8)
    let constraintPicRight = NSLayoutConstraint(item: picture, attribute: .right, relatedBy: .equal, toItem: …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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

在UITableView中发出警报的奇怪延迟

我有一些UITableView来自内部的数据array.我想UIAlertController点击显示,但我遇到了非常奇怪的延迟.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    print("tapped \(dispatcher.conversations[indexPath.row].name)") //this one works fine, no problems here

    let message = dispatcher.conversations[indexPath.row].desc + "\n\nDo you wanna play this?"
    let alertname = dispatcher.conversations[indexPath.row].name

    let alert = UIAlertController(title: alertname, message: message, preferredStyle: .alert)

    let actionOK = UIAlertAction(title: "Play", style: UIAlertActionStyle.default, handler: { (action) in
        //play the file
    })

    let actionCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
        //cancel the file
    })

    alert.addAction(actionOK)
    alert.addAction(actionCancel)

    self.present(alert, …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uialertcontroller

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