i just make implements mtqq protocol using iOS VOIP background mode.
In my code...
func connect()
{
NSLog("connect mtqq")
var _read : Unmanaged<CFReadStream>?
var _write : Unmanaged<CFWriteStream>?
CFStreamCreatePairWithSocketToHost( kCFAllocatorDefault, host, port, &_read, &_write )
input = _read!.takeRetainedValue()
output = _write!.takeRetainedValue()
CFReadStreamSetProperty( input, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP)
CFWriteStreamSetProperty( output, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP)
input!.delegate = self
output!.delegate = self
input!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
output!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
input!.open()
output!.open()
if( keepAlive == false )
{
keepAlive = true
UIApplication.sharedApplication().setKeepAliveTimeout(600, handler: {
if( self.connected )
{
self.ping()
}
else
{
self.connect()
}
})
}
}
this is my connection code if comment out NSLok("connect mtqq") in first line, it not work in background, tested in iOS simulator. or without iOS debugger this connection is closed when process is exited.
I found out How to handle socket connection's events when app is in background? in this article that there is some problem of simulator. Is clear?
0 comments:
Post a Comment