jas*_*san 42 react-native react-native-android react-native-ios
我不想撰写电子邮件.我只是希望能够从反应原生的应用程序在用户的设备(iOS和Android)上启动主电子邮件应用程序.
场景:我会在注册时向用户发送验证电子邮件.
Vis*_*iya 59
<Button onPress={() => Linking.openURL('mailto:support@example.com') }
title="support@example.com" />
Run Code Online (Sandbox Code Playgroud)
<Button onPress={() => Linking.openURL('mailto:support@example.com?subject=SendMail&body=Description') }
title="support@example.com" />
Run Code Online (Sandbox Code Playgroud)
<Button onPress={() => Linking.openURL('https://www.google.co.in/') }
title="www.google.co.in" />
Run Code Online (Sandbox Code Playgroud)
Dav*_*tte 11
不幸的是,没有一个答案是正确的。
我不想撰写电子邮件。我只希望能够启动主电子邮件应用程序
我希望有相同的行为:
Open Email App与带有魔术链接的Slack Onboarding大致相同。
我找到了带有库react-native-email-link的解决方案。您可以从React Native打开电子邮件客户端(用于“魔术链接”类型功能)。
mail.appiOS Simulator上没有。小智 10
Expo.io纯js/typescript解决方案:
import * as IntentLauncher from 'expo-intent-launcher';
// ...
public openMailClientIOS() {
Linking.canOpenURL('message:0')
.then(supported => {
if (!supported) {
console.log('Cant handle url')
} else {
return Linking.openURL('message:0')
.catch(this.handleOpenMailClientErrors)
}
})
.catch(this.handleOpenMailClientErrors)
}
public openMailClientAndroid() {
const activityAction = 'android.intent.action.MAIN'; // Intent.ACTION_MAIN
const intentParams: IntentLauncher.IntentLauncherParams = {
flags: 268435456, // Intent.FLAG_ACTIVITY_NEW_TASK
category: 'android.intent.category.APP_EMAIL' // Intent.CATEGORY_APP_EMAIL
};
IntentLauncher.startActivityAsync(activityAction, intentParams)
.catch(this.handleOpenMailClientErrors);
}Run Code Online (Sandbox Code Playgroud)
适用于 iOS 邮件,适用于 Android
Android 意图文档:https://developer.android.com/reference/android/content/Intent#ACTION_MAIN
世博会 IntentLauncher 文档:https ://docs.expo.io/versions/latest/sdk/intent-launcher/
为此,您可以使用react natives链接模块。这是指向模块https://facebook.github.io/react-native/docs/linking.html的链接。
例: Linking.openURL('mailto:example@gmail.com?subject=example&body=example')
在 iOS 上打开电子邮件应用程序:
Linking.canOpenURL('message:')
.then(supported => {
if (!supported) {
console.log('Cant handle url')
} else {
return Linking.openURL('message:')
}
})
.catch(err => {
console.error('An error occurred', err)
})
Run Code Online (Sandbox Code Playgroud)
cba*_*ock -1
我认为以下 npm 模块应该有您正在寻找的内容。不幸的是,它使用本机库,因此您必须运行一些反应本机链接。
https://www.npmjs.com/package/react-native-mail
| 归档时间: |
|
| 查看次数: |
31885 次 |
| 最近记录: |