CDVContacts.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import <Foundation/Foundation.h>
  18. #import <AddressBook/ABAddressBook.h>
  19. #import <AddressBookUI/AddressBookUI.h>
  20. #import <Cordova/CDVPlugin.h>
  21. #import "CDVContact.h"
  22. @interface CDVContacts : CDVPlugin <ABNewPersonViewControllerDelegate,
  23. ABPersonViewControllerDelegate,
  24. ABPeoplePickerNavigationControllerDelegate
  25. >
  26. {
  27. ABAddressBookRef addressBook;
  28. }
  29. /*
  30. * newContact - create a new contact via the GUI
  31. *
  32. * arguments:
  33. * 1: successCallback: this is the javascript function that will be called with the newly created contactId
  34. */
  35. - (void)newContact:(CDVInvokedUrlCommand*)command;
  36. /*
  37. * displayContact - IN PROGRESS
  38. *
  39. * arguments:
  40. * 1: recordID of the contact to display in the iPhone contact display
  41. * 2: successCallback - currently not used
  42. * 3: error callback
  43. * options:
  44. * allowsEditing: set to true to allow the user to edit the contact - currently not supported
  45. */
  46. - (void)displayContact:(CDVInvokedUrlCommand*)command;
  47. /*
  48. * chooseContact
  49. *
  50. * arguments:
  51. * 1: this is the javascript function that will be called with the contact data as a JSON object (as the first param)
  52. * options:
  53. * allowsEditing: set to true to not choose the contact, but to edit it in the iPhone contact editor
  54. */
  55. - (void)chooseContact:(CDVInvokedUrlCommand*)command;
  56. - (void)newPersonViewController:(ABNewPersonViewController*)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person;
  57. - (BOOL)personViewController:(ABPersonViewController*)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person
  58. property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue;
  59. /*
  60. * Launches the Contact Picker to select a single contact.
  61. *
  62. * arguments:
  63. * 1: this is the javascript function that will be called with the contact data as a JSON object (as the first param)
  64. * options:
  65. * desiredFields: ContactFields array to be returned back
  66. */
  67. - (void)pickContact:(CDVInvokedUrlCommand*)command;
  68. /*
  69. * search - searches for contacts. Only person records are currently supported.
  70. *
  71. * arguments:
  72. * 1: successcallback - this is the javascript function that will be called with the array of found contacts
  73. * 2: errorCallback - optional javascript function to be called in the event of an error with an error code.
  74. * options: dictionary containing ContactFields and ContactFindOptions
  75. * fields - ContactFields array
  76. * findOptions - ContactFindOptions object as dictionary
  77. *
  78. */
  79. - (void)search:(CDVInvokedUrlCommand*)command;
  80. /*
  81. * save - saves a new contact or updates and existing contact
  82. *
  83. * arguments:
  84. * 1: success callback - this is the javascript function that will be called with the JSON representation of the saved contact
  85. * search calls a fixed navigator.service.contacts._findCallback which then calls the success callback stored before making the call into obj-c
  86. */
  87. - (void)save:(CDVInvokedUrlCommand*)command;
  88. /*
  89. * remove - removes a contact from the address book
  90. *
  91. * arguments:
  92. * 1: 1: successcallback - this is the javascript function that will be called with a (now) empty contact object
  93. *
  94. * options: dictionary containing Contact object to remove
  95. * contact - Contact object as dictionary
  96. */
  97. - (void)remove:(CDVInvokedUrlCommand*)command;
  98. // - (void) dealloc;
  99. @end
  100. @interface CDVContactsPicker : ABPeoplePickerNavigationController
  101. {
  102. BOOL allowsEditing;
  103. NSString* callbackId;
  104. NSDictionary* options;
  105. NSDictionary* pickedContactDictionary;
  106. }
  107. @property BOOL allowsEditing;
  108. @property (copy) NSString* callbackId;
  109. @property (nonatomic, strong) NSDictionary* options;
  110. @property (nonatomic, strong) NSDictionary* pickedContactDictionary;
  111. @end
  112. @interface CDVNewContactsController : ABNewPersonViewController
  113. {
  114. NSString* callbackId;
  115. }
  116. @property (copy) NSString* callbackId;
  117. @end
  118. /* ABPersonViewController does not have any UI to dismiss. Adding navigationItems to it does not work properly, the navigationItems are lost when the app goes into the background.
  119. The solution was to create an empty NavController in front of the ABPersonViewController. This
  120. causes the ABPersonViewController to have a back button. By subclassing the ABPersonViewController,
  121. we can override viewWillDisappear and take down the entire NavigationController at that time.
  122. */
  123. @interface CDVDisplayContactViewController : ABPersonViewController
  124. {}
  125. @property (nonatomic, strong) CDVPlugin* contactsPlugin;
  126. @end
  127. @interface CDVAddressBookAccessError : NSObject
  128. {}
  129. @property (assign) CDVContactError errorCode;
  130. - (CDVAddressBookAccessError*)initWithCode:(CDVContactError)code;
  131. @end
  132. typedef void (^ CDVAddressBookWorkerBlock)(
  133. ABAddressBookRef addressBook,
  134. CDVAddressBookAccessError* error
  135. );
  136. @interface CDVAddressBookHelper : NSObject
  137. {}
  138. - (void)createAddressBook:(CDVAddressBookWorkerBlock)workerBlock;
  139. @end