Skip to content

Commit

Permalink
Step 15: Addressbook integration
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Jun 13, 2017
1 parent 4bceed0 commit 42659a7
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .tortilla/manuals/templates/step15.tmpl
@@ -0,0 +1,38 @@
In this step we are going to implement native address book integration, to automatically show only the users whose numbers are present in our address book.

`Ionic 2` is provided by default with a `Cordova` plug-in called `cordova-plugin-contacts`, which allows us to retrieve the contacts from the address book.

Let's start by installing the `Contacts` `Cordova` plug-in:

$ ionic cordova plugin add cordova-plugin-contacts --save
$ npm install --save @ionic-native/contacts

Then let's add it to `app.module.ts`:

{{{diffStep 15.2}}}

Since we're going to use `Sets` in our code, we will have to set the `Typescript` target to `es6` or enable `downlevelIteration`:

{{{diffStep 15.3}}}

Now we can create the appropriate handler in the `PhoneService`, we will use it inside the `NewChatPage`:

{{{diffStep 15.4}}}

{{{diffStep 15.5}}}

We will have to update the `users` publication to filter our results:

{{{diffStep 15.6}}}

Since they are now useless, we can finally remove our fake users from the db initialization:

{{{diffStep 15.7}}}

Obviously we will have to reset the database to see any effect:

$ npm run api:reset

To test if everything works properly I suggest to create a test user on your PC using a phone number which is already present in your phone's address book.

{{{navStep prevRef="https://angular-meteor.com/tutorials/whatsapp2/ionic/native-mobile" nextRef="https://angular-meteor.com/tutorials/whatsapp2/ionic/push-notifications"}}}

0 comments on commit 42659a7

Please sign in to comment.