Square的CardCase应用程序如何自动从地址簿中填充用户的详细信息? [英] How does Square's CardCase app automatically populate the user's details from the address book?

查看:119
本文介绍了Square的CardCase应用程序如何自动从地址簿中填充用户的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Square的新名片盒iOS应用程序具有创建帐户功能。点击它,它会显示一个表格PREPOPULATED与用户在地址簿中的条目。

Square's new card case iOS app has a "Create Account" feature. Tap it and it shows a form PREPOPULATED with the user's entry from the Address book.

这怎么可能?谁知道?我认为这是不可能的,以这种方式获取用户的信息。它不是iOS 5.0的东西,afaict。

How is this possible? Anyone know? I thought this was unpossible, to get the user's info this way. It's not an iOS 5.0 thing, afaict.

推荐答案

我能想出的唯一解决方案是使用设备名称然后搜索匹配的地址簿。这假设有人会使用特定的命名约定。例如,我使用'Nik的iPhone'作为我的设备名称。我也是我的地址簿中唯一的Nik,所以对于我的场景,可以使用之前的文本作为所有者名称。

the only solution I could come up with was using the device name and then searching the addressbook for a match. this assumes someone would use a particular naming convention. I for example use 'Nik's iPhone' as my device name. I am also the only Nik in my addressbook, so for my scenario is works well to use the text prior to 's as the owner name.

它使用了Erica Sadun的非常方便的ABAddressBook包装器, ABContactHelper
我留下了枚举代码,而不是在0处使用数组索引,因为可能会返回少量匹配,因此您可以展开以向用户提供选择他们的详细信息的选项。虽然不完全匹配方形案例解决方案效果很好。 imho。

It makes use of the very handy wrapper for ABAddressBook by Erica Sadun, ABContactHelper. I've left the enumeration code in instead of using array index at 0 as likely a small number of matches will be returned so you could expand to give the user an option to choose 'their' details. Which whilst not exactly matching the square case solution works well. imho.

NSString *firstname;
NSString *lastname;

NSString *ownerName = [[UIDevice currentDevice] name];

NSRange t = [ownerName rangeOfString:@"'s"];
if (t.location != NSNotFound) {
    ownerName = [ownerName substringToIndex:t.location];
} 

NSArray *matches = [ABContactsHelper contactsMatchingName:ownerName];
if(matches.count == 1){ 
    for (ABContact *contact in matches){
        firstname = [contact firstname];
        lastname = [contact lastname];

    }
}

这篇关于Square的CardCase应用程序如何自动从地址簿中填充用户的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆