繁体   English   中英

如何将联系人移动和复制到Gmail帐户iOS

[英]How to move and copy Contacts to the Gmail Account iOS

这是我获取设备联系人的代码,我想将这些联系人移动并复制到我的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上找到合适的东西。

经过快速搜索,我找到了这个库。 即使它不能完全满足您的需求,您也可以了解如何集成Google的API。

如果您决定不使用第三方库,则需要执行此操作。 (更多详细信息,您可以在这里找到。):

1)您需要授权

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM