在我的 iOS 应用程序中,我必须转换电话号码(在联系人中获取)并将其转换为国际格式(使用外部库自动发送 SMS)。我看到了libPhoneNumber但问题是我们必须输入国家代码,并且该应用程序必须在所有(几乎)国家工作,所以我不知道用户的国家是什么。
这是图书馆的工作方式:
let phoneUtil = NBPhoneNumberUtil()
let phoneNumberConverted = try phoneUtil.parse("0665268242", defaultRegion: "FR") // So I don't know the country of the user here
print(try? phoneUtil.format(phoneNumberConverted, numberFormat: NBEPhoneNumberFormat.INTERNATIONAL))