我的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 10(每台设备或每个应用程序)的语音识别是否有限制?
我的应用程序似乎无法与 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 }\nRun Code Online (Sandbox Code Playgroud)\n\ndefaultToSpeaker如果我改为就够了吗allowBluetooth?
PS 我知道这是一个相当愚蠢的问题,因为只需更改此行并检查会简单得多,但我现在没有 AirPods,所以我唯一的选择就是上传Testflight 的新构建(我想以最少的迭代来完成此操作)。
\n\n更新:(相当幼稚的方法 \xe2\x80\x94 但我需要的只是使用蓝牙耳机(如果可用):
\n\nfunc 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) 我有一个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) 我有一个带自定义单元格的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来自内部的数据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)