我正在尝试在iPhone上以VoIP模式设置套接字,以便在事件发生时我的应用可以被唤醒。我有一个简单的服务器将写入套接字当且仅当应用程序应该唤醒并与主要Web服务有关的事情。调用 CFReadStreamSetProperty() 在附加到套接字的流上似乎总是返回零,如果我没有弄错,则为FALSE,这意味着流不识别和/或接受属性值。我在之前的一个问题中读到这个设施在模拟器上不可用,所以我在一部真正的手机上试了一下,结果相同。
如何判断呼叫失败的原因?
代码如下:
- (id) init {
NSLog(@"NotificationClient init, host = %@", [self getNotificationHostName]);
CFHostRef notificationHost = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)[self getNotificationHostName]);
CFStreamCreatePairWithSocketToCFHost(kCFAllocatorDefault, notificationHost, [self getNotificationPort], &_fromServer, &_toServer);
BOOL status;
status = CFReadStreamOpen(_fromServer);
status = CFReadStreamSetProperty(_fromServer, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
NSLog(@"status from setting VoIP mode on socket is %d", status);
status = CFWriteStreamOpen(_toServer);
[self sendMessage:@"STRT" withArgument:@"iPhone"];
[self startReceivingMessages];
return self;
}
答案 0 :(得分:0)