I have a problem that I'm trying to understand: How come I receive from time to time Sentry errors telling me that an iPhone X or XR could not open the SMS url?
I have this error: Unable to open URL: sms:&body=...
But what's even weirder is that when I look at my Sentry breadcrumb, I realise that this error seems to happen when the user didn't even do the necessary action to open the SMS application!
The sms I send contains a URL that is generated by Firebase Dynamics Links.
Here is the code to generate the url of the sms and the code that sends the sms
InviteFriends.js
export default inviteFriends = () => {
let sharingToken = store.getState().user.share_token
firebase.dynamicLinks().buildShortLink({
link: `http://mywebsite?type=invite&sharing=${sharingToken}`,
domainUriPrefix: 'https://mylink.page.link',
navigation: {...},
android: {...},
ios: {...}
})
.then((url) => {
sms('', i18n.t('account.addFriends.searchUser.hint.sms', {link: url}))
})
sms.js
const sms = (phone = '', body = '') => {
const sep = Platform.OS === 'ios' ? '&' : '?'
const url = `sms:${phone}${body ? `${sep}body=${encodeURIComponent(body)}` : ''}`
const supported = await Linking.canOpenURL(url)
if (!supported) {
return Promise.reject(new Error('Provided URL can not be handled'))
}
return Linking.openURL(url)
}
What I find weird is that it seems to me that if opening the SMS application wasn't supported, I'd be supposed to get a message saying "Provided URL can not be handled" instead. Am I wrong ?
Thanks you,
Viktor
Related
I am trying to download a pdf generated through an own api that worked normally for me until yesterday, since then it has stopped working without any modification. Reviewing in developer mode through the metro everything seems to work correctly without any problems (I download the pdf normally), but when deploying the application in the playstore it closes unexpectedly, leaving me without knowing why this happens.
First I was using the React Native Fetch Blob, then I used React Native Blob Util hoping it would solve the problem but it keeps happening. Do you guys have any ideas for why does this happen?
The PDF file download this function:
const generarReciboPdf = async (datosDeuda:FormularioScreenParams,formaPago:ReactText,nroCheque?:string) =>{
const{config,fs} = ReactNativeBlobUtil
if (formaPago === 4 && (nroCheque == ""|| undefined)) {
return console.log('debe llenar todos los campos');
}
const { DownloadDir } = fs.dirs;
const token = await AsyncStorage.getItem('token');
let datosDeudaCompleto= {
...datosDeuda,
forma_pago:formaPago,
nro_cheque:nroCheque
}
let url = 'https://sys.arco.com.py/api/appRecibos/generarReciboPdf/'+JSON.stringify(datosDeudaCompleto)
// return console.log(url);
const options = {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true, // true will use native manager and be shown on notification bar.
notification: true,
mime:'application/pdf',
path: `${DownloadDir}/recibo_${datosDeuda.mes_deuda.replace(/ /g, "")}_${datosDeuda.razon_social.replace(/ /g, "")}.pdf`,
description: 'Downloading.',
},
};
config(options).fetch('GET', url,{Authorization :'Bearer '+token}).then((res) => {
console.log('se imprimio correctamte el pdf');
setErrorPdf(1)
}).catch((error)=>{
console.log(error);
setErrorPdf(-1);
});
}
Also, this error appears in Play Console: "PlayConsole Error Image".
PlayConsole Error Image
I have a problem with the situation where my React Native Expo app is running in the background / inactive modus and the app is brought back to the foreground / active mode as a result of the user opening a deep link to my app from the mobile browser.
When this situation occurs, my app needs to get a reference to the deep link in order to show the expected content to the user. The problem is that Linking.getInitialURL() always returns the link that was used to open the app from cold start and not the link that was used to bring the app back to foreground / active modus.
Advice on how to fix this problem would be greatly appreciated.
Found it out by myself :-)
useEffect(() => {
Linking.addEventListener('url', handleLinkEvent);
return () => {
Linking.removeEventListener('url', handleLinkEvent);
};
}, []);
For these cases you should use Linking.addEventListener
To complete #timboektoe's answer, react-navigation offers a subscribe function to listen to any URL received.
const subscribe = (listener) => {
const onReceiveURL = ({ url }) => { listener(url); };
const subscription = Linking.addEventListener('url', onReceiveURL);
return () => {
subscription.remove();
};
};
const linking = {
prefixes,
config,
getInitialURL,
subscribe,
};
Sharing.shareAsync(url, options)
Opens action sheet to share file to different applications which can handle this type of file.
Arguments
url (string) -- Local file URL to share.
options (object) --
A map of options:
mimeType (string) -- sets mimeType for Intent (Android only)
dialogTitle (string) -- sets share dialog title (Android and Web only)
UTI (string) -- (Uniform Type Identifier) the type of the target file (iOS only)
This is what they say on their page. I dont see any option to share text message along with a local image.
Is there any way to share both the image and text message ?
According to the docs, you should be able to use it like so for Android:
url = '<image-to-be-shared-local-url>';
messageText = 'Text that you want to share goes here';
const options = {
mimeType: 'image/jpeg',
dialogTitle: messageText,
};
Sharing.shareAsync(url, options);
But I would recommend to use react-native-share as this is more widely used and has more options for you to experiment with.
Here is the library documentation
Hope this helps :)
react-native-share still not compatible with expo. you have to use either expo-sharing or Share from react-native.
Example:
ShareMessage = async () => {
if (Platform.OS === "android") {
Share.share({
message: API.base_url + this.state.ShareProductName, // supporting android
url: this.state.share_images[0], // not supporting
title: this.state.ShareProductName,
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
} else if (Platform.OS === "ios") {
Share.share({
message:API.base_url + this.state.ShareProductName,
url: this.state.share_images[0],
title: this.state.ShareProductName, // not supporting
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
}
};
Is there a way to automatically send messages on WhatsApp using react-native? If not, can I use bridge to do it on android?
If this is only for whats app you can use this link
https://wa.me/whatsappphonenumber/?text=urlencodedtext
where whatsappphonenumber is country-code + phone-number without '+' sign
eg for India: 919876543210
and urlencodedtext is the message you want to send
this will open whatsapp chat and copy the message to the input field
you can use linking like this:
export const sendWhatsAppMessage = link => {
if (!isUndefined(link)) {
Linking.canOpenURL(link)
.then(supported => {
if (!supported) {
Alert.alert(
'Please install whats app to send direct message'
);
} else {
return Linking.openURL(link);
}
})
.catch(err => console.error('An error occurred', err));
} else {
console.log('sendWhatsAppMessage -----> ', 'message link is undefined');
}
};
Try this module
https://github.com/react-native-community/react-native-share
Hope this will be helpful!
I use send grid API for sending mail from my react native app but it returns this error.
i use this link: "https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md"
sendMail(){
const SENDGRID_API_KEY = "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";
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'test#example.com',
from: 'test#example.com',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);
}