开发者

Does Cocoa's CFHost support IDNs?

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)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜