1
我正在開發一個連接到聊天服務器的聊天客戶端應用程序。當我收到任何彈出式通知(例如,短信)時,iPhone會將應用置於非活動狀態 - 非常棒。我遇到的問題是,一旦通知被解僱,該應用程序已經失去了所有的網絡連接。我讀過其他地方,這不應該發生,但我不知道我錯過了什麼!保持iPhone網絡連接處於非活動狀態時保持活動狀態?
這是我用來創建讀寫流的代碼片段。
- (void) initNetworkCommunication {
//set up read and write streams
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
//connect to host at this address and this port
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"somewebsite.org", 3333, &readStream, &writeStream);
//open socket connection
inputStream = [(NSInputStream *)readStream retain];
outputStream = [(NSOutputStream *)writeStream retain];
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
}
當應用程序發送到後臺時,網絡連接也會丟失。我想解決這個問題,但現在的主要問題是斷開用戶的彈出式通知。