诸如whatsapp之类的应用如何显示仅使用该应用的联系人? [英] How does apps like whatsapp show contacts that are only using the app?

查看:252
本文介绍了诸如whatsapp之类的应用如何显示仅使用该应用的联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用电话身份验证的应用程序(如whatsapp)中:

In apps that use phone authentication like whatsapp:

当任何用户打开以检查其联系人时,whatsapp将仅显示您手机中正在使用whatsapp的联系人(例如他们过滤了您的联系人).

When any user opens to check his/her contacts, whatsapp will show only the contacts from your phone that are using whatsapp (like they filter your contacts).

我对实施类似内容的想法:

我可以将所有用户保存在数据库中(当他们通过我的应用进行身份验证时),现在,当我在活动中加载联系人时,我会检查联系人是否存在于数据库中,如果用户存在,则我添加他/她进入名单.

I can save all users in a database (when they authenticate with my app), now when I load contacts in an activity I check to see if the contact exist in the database, and if the user exist then I add him/her to the list.

问题:

如果我使用上述方法:

那么可以说我的数据库中有10,000个用户,那么每次我想在我的应用程序中显示某个用户的联系人时,遍历10,000个用户都是没有意义的.

Then lets say I have 10,000 users in the database, then it wont make sense to loop through 10,000 users every time I want to show contacts of a user inside my app.

问题:

您如何看待诸如whatsapp之类的应用来实现这样的事情?

How do you think apps like whatsapp implement such a thing?

推荐答案

您必须至少一次与联系人循环遍历用户,但您可以像WhatsApp一样巧妙地做到这一点.

You have to loop through your users with contacts at least one time but you can do it smartly just like WhatsApp do.

用户首次打开并在WhatsApp中注册时,他们会征求您的权限来读取您的联系人(来自API级别23),当用户在后台授予WhatsApp权限时,将其连接到其后端服务器(其中他们使用用户设备中可用的联系人保存其所有用户数据),并且响应此http请求,只有那些返回其帐号信息的号码在WhatsApp上注册,然后在WhatsApp本地将其保存为用户设备(SQLite或任何与数据库相关的服务) ),当用户打开WhatsApp的通讯录活动时,它会显示来自本地用户数据库而非服务器的数据.

When user first time open and register in WhatsApp they ask for your permission to read your contacts (From API Level 23) , when user grant the permission WhatsApp in background connect to their backend server (where they save their all user's data) with the contacts available in user's device and in response of this http request only those numbers returns with their account info which are registered on WhatsApp and then WhatsApp locally they save them user's device (SQLite or any database related service) and when user open WhatsApp's contacts activity it shows data from the local user database not the server.

现在的问题是:添加新联系人后会发生什么?

如果用户创建了新联系人,则WhatsApp将收到通知,然后WhatsApp再次使用新联系人的号码连接到其后端服务器.现在假设如果用户在创建新联系人时没有连接到Internet,那么会发生什么呢?

WhatsApp会将号码保存为本地号码的另一个表作为未检查的号码,然后在出现以下情况时再次将其保存用户将连接到互联网whatsapp将再次以相同类型的请求连接到其后端服务器.同样,在WhatApp的通讯录活动中,有一个名为强制刷新"的选项,它可以执行相同的操作,但不能在后台执行.

WhatsApp will be notified if user created new contact and then WhatsApp again connect to their backend server with the new contact's number. Now suppose if user was not connected to the internet when creating the new contact then what happen?

WhatsApp will save the number to another table of their local database as not checked number and then once again when user will connect to internet whatsapp will again connect to their backend server with same type of request. Also in WhatApp's contacts activity there is a option called force refresh which do the same thing but not in background.

现在的问题是,这样做有什么好处?

  • 数据使用量少,非常适合用户体验
  • 每次用户打开联系人活动时都不需要与服务器联系.这对用户体验也很重要.

这篇关于诸如whatsapp之类的应用如何显示仅使用该应用的联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆