简体   繁体   中英

iPhone OS 3.x - background asyncsockets (if statement is not workable?)

I am trying to implement the background mode with async socket. The following are a few codes:

CFReadStreamRef theReadStream;
CFWriteStreamRef theWriteStream;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) {        
    CFReadStreamSetProperty (theReadStream,  kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
    CFWriteStreamSetProperty(theWriteStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP); 
}  

I know kCFStreamNetworkServiceType and kCFStreamNetworkServiceTypeVoIP are available in iPhone with iOS started at 4.0.

The above codes were workable indeed when I built into iPhone with iOS started at 4.0.

However, I could not build the above codes into iPhone with iOS 3.1 successfully.

I have added the statement, ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) , to the above codes.

I don't know why I could not enter the program at all especially I have added the if statement.

I think you are getting compile time error because you are using kCFStreamNetworkServiceType and kCFStreamNetworkServiceTypeVoIP in your code which is not available in iOS 3.1. Its available in iOS 4.0 onwards. So you should use #if kind of macros to get rid of that error. Hope that helps to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM