我有一个问题是通过UDP在swift中通过CocoaAsyncSocket发送音频.
首先,我运行下面的代码开始监听4444 UDP端口.
vlc --demux=rawaud --rawaud-channels=1 --rawaud-samplerate=48000 udp://@:4444
Run Code Online (Sandbox Code Playgroud)
之后我在iPad2上运行我的应用程序并按连接.
import UIKit
import CocoaAsyncSocket
import AVFoundation
class ViewController: UIViewController , GCDAsyncUdpSocketDelegate {
var avAudioEngine : AVAudioEngine?
@IBAction func btnAction(sender: UIButton) {
avAudioEngine = AVAudioEngine()
let input = avAudioEngine?.inputNode
let socket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
do {
try socket.bindToPort(4445)
try socket.connectToHost("192.168.0.137",onPort : 4444)
try socket.beginReceiving()
input?.installTapOnBus(0, bufferSize: 2048, format: input?.inputFormatForBus(0), block: { (buffer : AVAudioPCMBuffer, timeE: AVAudioTime) -> Void in
socket.sendData(self.toNSData(buffer), withTimeout: 0, tag: 0)
})
avAudioEngine?.prepare()
try avAudioEngine?.start()
// with …
Run Code Online (Sandbox Code Playgroud) 我有一个问题是在异步过程中获取值.
我的班级是:
public class PostService: NSObject {
var result : String = String()
//this is my function
func request(var dataPost : String, var destination : String)->String{
let request = NSMutableURLRequest(URL: NSURL(string: destination as String)!)
request.HTTPMethod = "POST"
let postString = dataPost
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
println("error=\(error)")
return
}
let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
self.result = responseString as String!
}
task.resume()
//problem is here that result …
Run Code Online (Sandbox Code Playgroud) 我想将x-frame-options作为同源添加到在S3存储桶上为我的应用程序提供服务的AWS CloudFront服务。
我不想添加新的Lambda函数来编辑请求标头。
其实我在附件中找到了一个地方:
CloudFront Distributions -> My Distribution settings -> Origins and Origin Groups -> S3 Content item that代表我的应用程序 -> add Origin Custom Headers -> Header name: x-frame-options , Value : sameorigin
但是当部署完成时,仍然在 S3 存储桶文件和 URL 的所有相关请求中获取旧标头。
我如何在没有任何 Lambda 函数的情况下添加到标头,而只是直接使用现有的 AWS CloudFront 面板?