ionic添加cordova插件-Contacts

版权声明:本文为博主gzgchzc原创文章,转载必须注明出处。http://blog.gzvtc.cc/ https://blog.csdn.net/qq_33561700/article/details/53885856

gzgchzc博客最新更新地址:http://blog.gzvtc.cc/

Contacts
在设备上创建、删除和搜索通讯录。

cordova plugin add cordova-plugin-contacts

Examples

module.controller('MyCtrl', function($scope, $cordovaContacts, $ionicPlatform) {
  $scope.addContact = function() {
    $cordovaContacts.save($scope.contactForm).then(function(result) {
      // Contact saved
    }, function(err) {
      // Contact error
    });
  };

  $scope.getAllContacts = function() {
    var options = {};
      options.filter = "";
      options.multiple = true;
    $cordovaContacts.find(options).then(function(allContacts) { //omitting parameter to .find() causes all contacts to be returned
      $scope.contacts = allContacts;
    }
  };

  $scope.findContactsBySearchTerm = function (searchTerm) {
    var opts = {                                           //search options
      filter : searchTerm,                                 // 'Bob'
      multiple: true,                                      // Yes, return any contact that matches criteria
      fields:  [ 'displayName', 'name' ]                   // These are the fields to search for 'bob'.
      desiredFields: [id];    //return fields.
    };

    if ($ionicPlatform.isAndroid()) {
      opts.hasPhoneNumber = true;         //hasPhoneNumber only works for android.
    };

    $cordovaContacts.find(opts).then(function (contactsFound) {
      $scope.contacts = contactsFound;
    };
  }

  $scope.pickContactUsingNativeUI = function () {
    $cordovaContacts.pickContact().then(function (contactPicked) {
      $scope.contact = contactPicked;
    }
  }

});
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页