使用 NSNumberFormatterStyle 创建 (US) phone 数字样式

Use NSNumberFormatterStyle to create a (US) phone number style

我正在尝试找到一种使用 NSNumberFormatter 将输入的数字字符串格式化为美国 phone 数字样式的方法。

例如: 4155552671应该是+1-415-555-2671(如果我没记错的话)

我想知道是否有一种简单的方法可以使用本机 API(NSNumberFormatterStyle?)来执行此操作,而不是使用我自己的逻辑来修改字符串。 有什么想法吗? 谢谢

这不是适合 NSNumberFormatter 的任务。

也许 this answer 可以提供帮助。

还有一个 iOS ported version of Google's phone number library 可能会有所帮助,您可能正在寻找 RFC3966 输出或国际输出的变体。