1
私はチャットサーバーに接続するチャットクライアントアプリケーションに取り組んでいます。ポップアップ通知(たとえば、SMSメッセージ)を受信すると、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];
}
アプリがバックグラウンドで送信されると、ネットワーク接続も失われます。私もそれを修正したいと思いますが、今の主な問題は、ユーザーを切断するポップアップ通知です。