这是我获取设备联系人的代码,我想将这些联系人移动并复制到我的 Gmail 帐户。
CNContactStore *contactStore = [[CNContactStore alloc] init];
NSArray *keys = [[NSArray alloc]initWithObjects:CNContactJobTitleKey,CNContactNoteKey,CNContactBirthdayKey, CNContactThumbnailImageDataKey, CNContactPhoneNumbersKey,CNContactEmailAddressesKey,CNContactTypeKey, CNContactViewController.descriptorForRequiredKeys,CNContainerIdentifierKey, nil];
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys];
request.predicate = nil;
[contactStore enumerateContactsWithFetchRequest:request error:nil usingBlock:^(CNContact* __nonnull contact, BOOL* __nonnull stop){
}];
最佳答案
您可能要检查的最基本的地方是Google Contacts API .
但可以肯定的是,这将非常耗时且不容易。如果那不是一个选项,您可以考虑在 GitHub 上找到合适的东西。
通过快速搜索,我找到了 this图书馆。即使它不能完全满足您的需求,您也可以深入了解应该如何集成 Google 的 API。
如果您决定不使用第三方库,这就是您需要做的。 (您可以找到更多详细信息 here。):
1) 你需要authorize ;
2) 之后您可以发送创建新联系人的请求:
POST /m8/feeds/contacts/default/full
Content-Type: application/atom+xml
GData-Version: 3.0
...
一个请求体:
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:gd="http://schemas.google.com/g/2005">
<atom:category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/contact/2008#contact"/>
<gd:name>
<gd:givenName>Elizabeth</gd:givenName>
<gd:familyName>Bennet</gd:familyName>
<gd:fullName>Elizabeth Bennet</gd:fullName>
</gd:name>
<atom:content type="text">Notes</atom:content>
<gd:email rel="http://schemas.google.com/g/2005#work"
primary="true"
address="liz@gmail.com" displayName="E. Bennet"/>
<gd:email rel="http://schemas.google.com/g/2005#home"
address="liz@example.org"/>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#work"
primary="true">
(206)555-1212
</gd:phoneNumber>
<gd:phoneNumber rel="http://schemas.google.com/g/2005#home">
(206)555-1213
</gd:phoneNumber>
<gd:im address="liz@gmail.com"
protocol="http://schemas.google.com/g/2005#GOOGLE_TALK"
primary="true"
rel="http://schemas.google.com/g/2005#home"/>
<gd:structuredPostalAddress
rel="http://schemas.google.com/g/2005#work"
primary="true">
<gd:city>Mountain View</gd:city>
<gd:street>1600 Amphitheatre Pkwy</gd:street>
<gd:region>CA</gd:region>
<gd:postcode>94043</gd:postcode>
<gd:country>United States</gd:country>
<gd:formattedAddress>
1600 Amphitheatre Pkwy Mountain View
</gd:formattedAddress>
</gd:structuredPostalAddress>
</atom:entry>
关于ios - 如何将联系人移动和复制到 Gmail 帐户 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40631606/