开发者

How to set VoIP mode on a socket in iOS 4

开发者 https://www.devze.com 2023-01-27 12:31 出处:网络
I\'m trying to set up a socket in VoIP mode on an iPhone, so that my app can be woken when an event happens.I have a simple server that will write to the socket if and only if the app should wake up a

I'm trying to set up a socket in VoIP mode on an iPhone, so that my app can be woken when an event happens. I have a simple server that will write to the socket if and only if the app should wake up and talk to the main web service about something. Calling CFReadStreamSetProperty() on the stream attached to the socket always seems to return zero, which if I'm not mistaken is FALSE, meaning the stream did not recognize and/or accept the property value. I read in a previous question that this facility is not available on the simulator, so I tried it on a real phone, with the same result.

How can I figure out why the call is failing?

The code is below:

- (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;
}


Hmm... it looks like there were two problems. First, you need to set the property before opening the stream. And second, it looks like it only works if you are on the main thread when you do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消