1

WINAPI has methods to convert Unicode host names to Punycode. Does Cocoa/Cocoa Touch have a similar mechanism?

Plumenator
  • 1,682
  • 3
  • 20
  • 49

2 Answers2

2

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;
mstroeck
  • 21
  • 3
0

Check out SBPunyCode (updated link)

Shebuka
  • 3,148
  • 1
  • 26
  • 43
catlan
  • 25,100
  • 8
  • 67
  • 78