WINAPI ha开发者_C百科s methods to convert Unicode host names to Punycode. Does Cocoa/Cocoa Touch have a similar mechanism?
There's a little hack that works without any external libraries. Assuming you have a Unicode URL in theUrl, you can do:
NSURL *urlToLoad = nil;
NSPasteboard * pasteboard = [NSPasteboard pasteboardWithName:@"RandomPB"];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
@try
{
if ([pasteboard setString:theUrl forType:NSStringPboardType])
urlToLoad = [WebView URLFromPasteboard:pasteboard];
}
@catch (NSException * exception)
{
urlToLoad = nil;
NSLog(@"Can't create URL from string '%@'.", theUrl);
}
return urlToLoad;
Check out SBPunyCode (updated link)
精彩评论