我想为iOS设备编写一个Airplay接收器,这样我就可以将iPhone上的照片/视频分享给其他iOS设备。首先,我必须发布Airplay服务,并希望它可以被iPhone或iPad等其他iOS设备检测到。我写了一个发布服务的试点程序,遗憾的是其它iOS设备无法检测到它。我的代码有什么问题?
@IBAction func StartPublish(_ sender: UIButton)
{
print("Start publishing...")
if (airplayService == nil)
{
airplayService = NetService(domain: "", type: "_airplay._tcp.", name: "BaoWJ", port: 7000)
airplayService.delegate = self
let dataModel = "AppleTV2,1".data(using: String.Encoding.utf8)!
let dataDeviceID = "DC:37:14:0C:6C:D6".data(using: String.Encoding.utf8)!
let dataFeature = "0x39F7".data(using: String.Encoding.utf8)!
let dataVer = "130.14".data(using: String.Encoding.utf8)!
let txtAirplayDic = ["deviceid": dataDeviceID,
"features": dataFeature,
"model": dataModel,
"srcvers": dataVer
]
let txtAirplayData = NetService.data(fromTXTRecord: txtAirplayDic)
airplayService.setTXTRecord(txtAirplayData)
}
airplayService.publish()
if (raopService == nil)
{
raopService = NetService(domain: "", type: "_raop._tcp.", name: "DC37140C6CD6@BaoWJ", port: 45192)
raopService.delegate = self
let dataAM = "AppleTV2,1".data(using: String.Encoding.utf8)!
let dataCH = "2".data(using: String.Encoding.utf8)!
let dataCN = "0,1,2,3".data(using: String.Encoding.utf8)!
let dataDA = "true".data(using: String.Encoding.utf8)!
let dataET = "0,3,5".data(using: String.Encoding.utf8)!
let dataFT = "0x39F7".data(using: String.Encoding.utf8)!
let dataMD = "0,1,2".data(using: String.Encoding.utf8)!
let dataPW = "false".data(using: String.Encoding.utf8)!
let dataSV = "false".data(using: String.Encoding.utf8)!
let dataSR = "44100".data(using: String.Encoding.utf8)!
let dataSS = "16".data(using: String.Encoding.utf8)!
let dataTP = "UDP".data(using: String.Encoding.utf8)!
let dataVN = "65537".data(using: String.Encoding.utf8)!
let dataVS = "130.14".data(using: String.Encoding.utf8)!
let dataSF = "0x4".data(using: String.Encoding.utf8)!
let txtRaopDic = ["am": dataAM,
"ch": dataCH,
"cn": dataCN,
"da": dataDA,
"et": dataET,
"ft": dataFT,
"md": dataMD,
"pw": dataPW,
"sv": dataSV,
"sr": dataSR,
"ss": dataSS,
"tp": dataTP,
"vn": dataVN,
"vs": dataVS,
"sf": dataSF
]
let txtRaopData = NetService.data(fromTXTRecord: txtRaopDic)
raopService.setTXTRecord(txtRaopData)
}
raopService.publish()
}