在没有提示的情况下反应本机读取用户电子邮件

问题描述 投票:10回答:1

如果我在Google Play上安装了应用,我会注意到它会告诉我应用所需的权限。一旦它在应用程序中执行它也会提示我。这一切都很好。

我想阅读Google或Apple帐户的电子邮件 - 而不会提示最终用户收到电子邮件。

我不想将电子邮件用作身份验证令牌,而是预先填写“订阅新闻信函”字段。然后,用户可以打开或关闭(或选择添加其他电子邮件)。

android ios reactjs react-native
1个回答
9
投票

如果我的问题正确,您需要获取当前登录用户的主电子邮件地址,该地址可用于预填某种表格(例如注册表格)

对于Android

尝试以下反应原生包装库react-native-account-manager

使用上述链接自述文件中的说明进行设置后,请使用以下代码检索已登录的Google帐户列表。

请注意,如果没有与该设备关联的Google帐户,则可能会产生一个空列表

import AccountManager from 'react-native-account-manager';

AccountManager.getAccountsByType('accountName').then((accounts) => {
// console.log('available accounts', accounts);
let [firstAccount] = accounts;

AccountManager.getUserData(firstAccount, 'storedKey').then((storedData) => {
// console.log('stored data for storeKey', storedData);

AccountManager.setUserData(account, 'storedKey', JSON.stringify({foo: "bar"})).then(() => {
  // console.log('data successfully stored');
  })
});
})

对于iOS

厄运

Apple不会向应用开发者公开iPhone用户的详细信息,例如他们的电子邮件地址,密码或信用卡详细信息。

另一种方法是使用icloud令牌来创建用户。你可以使用following guide to do it

对于使用react-native使用react-native-icloud-user-tokenlibrary获取iCloud令牌的包装器

荣誉

© www.soinside.com 2019 - 2024. All rights reserved.