2
我想了一會兒發送數據到OutputStream與其他設備進行通信。 (爲此,我使用外部附件框架)但該功能不起作用。我有錯誤無法找到成員「寫」。我希望有人能幫我找到解決辦法。謝謝。 ?swift OutputStream無法找到成員「寫」
func _writeData() {
while (_session.outputStream.hasSpaceAvailable && _write.length > 0) {
var bytesWritten: Int = _session?.outputStream.write(_write.bytes, _write.length);
if(bytesWritten == -1){
println("write error");
break;
}
else if (bytesWritten > 0){
_write.replaceBytesInRange(NSMakeRange(0, bytesWritten), withBytes: nil, length: 0);
}
}
}
//high level write data method
func writeData(data: NSData) {
if(_write == nil) {
_write = NSMutableData.alloc();
}
_write.appendData(data);
self._writeData();
}
的誤差--------> VAR bytesWritten:INT = _session .outputStream.write(_write.bytes,_write.length);
在有些情況下我打開和關閉會話
//打開帶有附件的會話,並設置在默認的運行循環 FUNC的openSession(附件輸入和輸出流的功能:EAAccessory,withProtocolString protocolString :字符串) - > ObjCBool {
_session = EASession(accessory: accessory, forProtocol: protocolString);
if(_session != nil) {
_session.inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode);
_session.inputStream.open()
_session.outputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode);
_session.outputStream.open();
} else {
println("Creating session failed");
}
return (_session != nil);
}
//close the session with the accessory
func closeSession() {
_session.inputStream.close();
_session.inputStream.removeFromRunLoop(NSRunLoop(), forMode: NSDefaultRunLoopMode);
_session.outputStream.close();
_session.outputStream.removeFromRunLoop(NSRunLoop(), forMode: NSDefaultRunLoopMode);
}
我不會開始使用功能「_」它eslewhere應用於雨燕測試它 - 如果你的目的是爲了紀念功能爲私有貝塔4這是可能與即private func yourFunction()。我也不會把_放在變量名之前;) – AppHandwerker