如何通过Expo获取设备电话号码?

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

我想知道所连接设备的电话号码。 我尝试了expo-contacts和expo-device库,但无法获得我想要的信息。我该怎么办?

import * as Contacts from "expo-contacts";
import * as Device from "expo-device";

  useEffect(() => {
    (async () => {
      const { status } = await Contacts.requestPermissionsAsync();
      if (status === "granted") {
        const { data } = await Contacts.getContactsAsync({
          fields: [Contacts.Fields.PhoneNumbers],
        });

        if (data.length > 0) {
          const contact = data[0];
          console.log("contact", contact);
          
          console.log(Device);
        }
      }
    })();
  }, []);
android ios react-native expo
1个回答
0
投票

如果您要求在设备上激活电话号码,那么您可以使用“react-native-device-number”库。

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