I'm trying to convert the url to IP address during app startup by using the method gethostbyname, and in this way, let the system cache the IP address, so that in later webview and NSURLSession network requests, can skip the DNS stage and send requests directly to the IP address.
My question is, first of all, is gethostbyname safe? I see that gethostbyname is a synchronous method and may cause crash, so I put it in a background current queue and use try-catch to protect it, will this prevent crashes from happening?
Secondly, is gethostbyname the best solution to this problem? I know CFHost also has API to convert url to ip, but CFHostStartInfoResolution and CFHostGetAddressing are already marked as deprecate, is there any other solution?
7
0
1.7k