iOS 地址簿编程指南(Address Book Programming Guide for iOS)

简介: iOS 地址簿编程指南(Address Book Programming Guide for iOS) 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

iOS 地址簿编程指南(Address Book Programming Guide for iOS)

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino否则,出自本博客的文章拒绝转载或再转载,谢谢合作。


  • 概述(Introduction)

iOS 的地址簿技术提供了一种方式用于存储人们的联系人信息和其它个人信息在一个中心数据库中,并在应用之间共享该信息。该技术由几部分组成:

  • 地址簿框架提供对联系人信息的访问。

  • 地址簿用户界面框架提供用户界面用于显示信息。

  • 地址簿数据库用于存储信息。

  • 联系人应用为用户提供一种访问他们的联系信息的方式。

本文档涵盖了地址簿技术的关键概念,而且说明了可执行的基本操作。当你添加该技术到你的应用时,用户就能在你的应用中使用他们在其它应用诸如邮件和文本中使用的联系信息。该文档告诉你如何来做如下的事情:
  • 访问用户的地址簿数据库
  • 提示用户联系信息
  • 显示联系信息给用户
  • 更改用户的地址簿数据库
要想有效地使用本文档,你应该已经理解了导航控制器和视图控制器,并且理解代理和协议。
注意:在 Mac OS X 上使用过地址簿技术的开发者应该了解该技术的编程接口与 iOS 上不同。

The Address Book technology for iOS provides a way to store people’s contact information and other personal information in a centralized database, and to share this information between applications. The technology has several parts:

    • The Address Book framework provides access to the contact information.

    • The Address Book UI framework provides the user interface to display the information.

    • The Address Book database stores the information.

    • The Contacts application provides a way for users to access their contact information.

This document covers the key concepts of the Address Book technology and explains the basic operations you can perform. When you add this technology to your application, users will be able to use the contact information that they use in other applications, such as Mail and Text, in your application. This document tells you how to do the following:
    • Access the user’s Address Book database
    • Prompt the user for contact information
    • Display contact information to the user
    • Make changes to the user’s Address Book database

To get the most out of this document, you should already understand navigation controllers and view controllers, and understand delegation and protocols.

Note: Developers who have used the Address Book technology on Mac OS X should be aware that the programming interface for this technology is different on iOS.

本文档的组织结构(Organization of This Document)

本文档包含如下章节:


This document contains the following chapters:

    • “Quick Start Tutorial”

       gets you up and running by showing you how to create a simple application that uses the Address Book technology.
    • “Building Blocks: Working with Records and Properties”

       describes how to create an address book object, how to create person and group records, and how to get and set properties.
    • “User Interaction: Prompting for and Displaying Data”

       describes how to use the views provided by the Address Book UI framework to display a contact, let the user select a contact, create a new contact, and edit a contact.
    • “Direct Interaction: Programmatically Accessing the Database”

       describes the ways your application can read and write contact information directly.

参见(See Also)

下面的文档讨论了你应该理解的一些基本概念,以便充分利用本文档:

  • iOS 应用编程指南

     引导新接触 iOS 平台的开发者浏览可用的技术,以及如何使用这些技术构建应用。这篇文档包括窗口、视图和视图控制器的相关讨论。
  • 界面构建器用户指南

     说明了如何使用界面构建器创建应用。它包括一个应用的用户界面相关的讨论,以及从界面到代码建立连接。( Xcode 4 User Guide 的 Edit User Interfaces  部分取代了该文档 
  • Cocoa 基础指南

     和 Objective-C 编程语言 讨论了许多你所需要的编写应用的基本概念。它包括代理和协议相关的讨论。
下面的文档包含有关地址簿框架的额外信息:

The following documents discuss some of the fundamental concepts you should understand in order to get the most out of this document:

    • iOS App Programming Guide

       guides developers who are new to the iOS platform through the available technologies and how to use them to build applications. It includes relevant discussion of windows, views, and view controllers.
    • Interface Builder User Guide

       explains how to use Interface Builder to create applications. It includes relevant discussion of the user interface for an application and making connections from the interface to the code.
    • Cocoa Fundamentals Guide

       and The Objective-C Programming Language discuss many basic concepts you will need to write any application. It includes relevant discussion of delegation and protocols.

The following documents contain additional information about the Address Book frameworks:

    • Address Book Framework Reference for iOS

       describes the API for direct interaction with records in the Address Book database.
    • Address Book UI Framework Reference for iOS

       describes the controllers that facilitate displaying, editing, selecting, and creating records in the Address Book database, and their delegate protocols.
  • 快速起步教程(Quick Start Tutorial)

在本教程中,你将构建一个简单的应用,该应用提示用户从他/她的联系人列表中选择一个联系人,并呈现选择的联系人的名字和电话号码。

In this tutorial, you will build a simple application that prompts the user to choose a person from his or her contacts list and then shows the chosen person’s first name and phone number.

    • 创建并配置项目(Create and Configure the Project)

1、在 Xcode 中,从 Single View Application 模板创建一个新的项目。

2、链接地址簿用户界面和地址簿框架到你的项目。

提示:如果你没有链接这两个框架,项目就会构建失败(出现一个链接错误)。

      1. In Xcode, create a new project from the Single View Application template.

      2. Link

         the Address Book UI and Address Book frameworks to your project.
Important: The project will fail to build (with a linker error) if you do not link against both of these framework.
    • 创建用户界面和头文件(Create the UI and Header File)

While you are creating the user interface, you will take advantage of Xcode’s ability to declare the necessary actions and properties, creating the majority of the header file for you.

      1. Open the main storyboard file (MainStoryboard.storyboard).

      2. Add

         a button and two labels to the view by dragging them in from the library panel. Arrange them as shown in Figure 1-1.
      3. Open the assistant editor.

      4. Connect

         the button to a new action method called showPicker: on the view controller.
        1. This sets the target and action of the button in the storyboard, adds a declaration of the method to the header file, and adds a stub implementation of the method to the implementation file. You will fill in the stub implementation later.

    • Connect

       the two labels to two new properties called firstName and phoneNumber of the view controller.
    1. A window in Interface Builder with a button in the center, titled "Tap Me!", and two text labels below it that say "First Name" and "Last Name".

    This creates a connection in the storyboard, adds a declaration of the properties to the header file, and adds the  @synthesize line for the properties in the implementation file. Figure 1-1   Laying out the interface A window in Interface Builder with a button in the center, titled "Tap Me!", and two text labels below it that say "First Name" and "Last Name".At this point  ViewController.h, the header file for the view controller, is almost finished. At the end of the  @interface line, declare that the view controller class adopts the ABPeoplePickerNavigationControllerDelegate protocol by adding the following: <ABPeoplePickerNavigationControllerDelegate> Listing 1-1  shows the finished header file. Listing 1-1   The finished header file
    #import <UIKit/UIKit.h>
    #import <AddressBookUI/AddressBookUI.h>
     
    @interface ViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate>
     
    @property (weak, nonatomic) IBOutlet UILabel *firstName;
    @property (weak, nonatomic) IBOutlet UILabel *phoneNumber;
     
    - (IBAction)showPicker:(id)sender;
     
    @end

      • 编写实现部分(Write the Implementation)
      • 构建和运行应用(Build and Run the Application)
    • 构建块:使用记录和属性(Building Blocks:Working with Records and Properties)
      • 地址簿(Address Books)
      • 记录(Records)
        • 联系人记录(Person Records)
        • 分组记录(Group Records)
      • 属性(Properties)
        • 单值属性(Single-Value Properties)
        • 多值属性(Multivalue Properties)
          • 可变的多值属性(Mutable Multivalue Properties)
          • 街道地址(Street Addresses)
    • 用户界面:提示并显示数据(User Interaction: Prompting for and Displaying Data)
      • 哪些界面可用(What’s Available)
      • 提示用户选择联系人记录(Prompting the User to Choose a Person Record)
      • 显示并编辑联系人记录(Displaying and Editing a Person Record)
      • 提示用户创建新的联系人记录(Prompting the User to Create a New Person Record)
      • 提示用户从已有数据创建新的联系人记录(Prompting the User to Create a New Person Record from Existing Data)
    • 直接交互:编程访问数据库(Direct Interaction: Programmatically Accessing the Database)
      • 使用记录标识(Using Record Identifiers)
      • 使用联系人记录(Working with Person Records)
      • 使用分组记录(Working with Group Records)
    • 文档修订历史(Document Revision History)



    目录
    相关文章
    |
    2月前
    |
    Swift iOS开发 UED
    揭秘一款iOS应用中令人惊叹的自定义动画效果,带你领略编程艺术的魅力所在!
    【9月更文挑战第5天】本文通过具体案例介绍如何在iOS应用中使用Swift与UIKit实现自定义按钮动画,当用户点击按钮时,按钮将从圆形变为椭圆形并从蓝色渐变到绿色,释放后恢复原状。文中详细展示了代码实现过程及动画平滑过渡的技巧,帮助读者提升应用的视觉体验与特色。
    63 11
    |
    3月前
    |
    Swift iOS开发 UED
    【绝妙创意】颠覆你的视觉体验!揭秘一款iOS应用中令人惊叹的自定义动画效果,带你领略编程艺术的魅力所在!
    【8月更文挑战第13天】本文通过一个具体案例,介绍如何使用Swift与UIKit在iOS应用中创建独特的按钮动画效果。当按钮被按下时,其形状从圆形变化为椭圆形,颜色则从蓝色渐变为绿色;释放后,动画反向恢复原状。利用UIView动画方法及弹簧动画效果,实现了平滑自然的过渡。通过调整参数,开发者可以进一步优化动画体验,增强应用的互动性和视觉吸引力。
    52 7
    |
    3月前
    |
    安全 测试技术 调度
    iOS开发-多线程编程
    【8月更文挑战第12天】在iOS开发中,属性的内存管理至关重要,直接影响应用性能与稳定性。主要策略包括:`strong`(强引用),保持对象不被释放;`weak`(弱引用),不保持对象,有助于避免循环引用;`assign`(赋值),适用于基本数据类型及非指针对象类型;`copy`(复制),复制对象而非引用,确保不变性。内存管理基于引用计数,利用自动引用计数(ARC)自动管理对象生命周期。此外,需注意避免循环引用,特别是在block中。最佳实践包括理解各策略、避免不必要的强引用、及时释放不再使用的对象、注意block中的内存管理,并使用工具进行内存分析。正确管理内存能显著提升应用质量。
    |
    4月前
    |
    移动开发 开发工具 Android开发
    探索安卓与iOS开发的差异:平台特性与编程实践
    【7月更文挑战第8天】在移动开发的广阔天地中,安卓和iOS这两大操作系统各自占据着半壁江山。它们在用户界面设计、系统架构及开发工具上展现出截然不同的特色。本文将深入探讨这两个平台在技术实现和开发生态上的关键差异,并分享一些实用的开发技巧,旨在为跨平台开发者提供有价值的见解和建议。
    |
    4月前
    |
    IDE 开发工具 Android开发
    安卓与iOS开发环境对比分析:选择适合自己的编程平台
    移动应用开发的两大阵营——安卓和iOS,各自拥有不同的开发环境和工具集。本文通过深入比较这两个平台的编程语言、集成开发环境(IDE)、用户界面设计、测试框架以及部署流程,旨在为开发者提供一个全面的视角来选择最符合个人或项目需求的开发环境。
    |
    5月前
    |
    安全 IDE Android开发
    探索Android与iOS开发的差异:平台特性与编程实践
    【6月更文挑战第17天】在移动应用开发的广阔天地中,Android和iOS两大平台各自占据半壁江山。它们在用户群体、系统架构以及开发环境上的差异,为开发者带来了不同的挑战和机遇。本文深入探讨了这两个平台在技术实现、界面设计、性能优化等方面的主要区别,并提供了实用的开发建议,旨在帮助开发者更好地理解各自平台的特性,从而创造出更加优秀的移动应用。
    |
    Android开发 iOS开发
    iOS 逆向编程(四)实操 Jailbreak 进阶必备软件
    iOS 逆向编程(四)实操 Jailbreak 进阶必备软件
    102 0
    |
    数据安全/隐私保护 iOS开发 开发者
    iOS 逆向编程(三)实操 Jailbreak 详细流程
    iOS 逆向编程(三)实操 Jailbreak 详细流程
    247 1
    |
    iOS开发
    实战编程·使用SwiftUI从0到1完成一款iOS笔记App(五)(3)
    实战编程·使用SwiftUI从0到1完成一款iOS笔记App(五)
    155 0
    |
    前端开发 数据处理 iOS开发
    实战编程·使用SwiftUI从0到1完成一款iOS笔记App(五)(2)
    实战编程·使用SwiftUI从0到1完成一款iOS笔记App(五)
    91 0