onesignal alert notification force close after open notification in ios - ios

after open the notification from notification center, the application running only splash screen and force close after splash screen. my application in android is normal open the alert. my ios version 12.2. my code is here:
initializeApp()
{
this.platform.ready().then(() => {
if (this.platform.is('cordova'))
{
this.oneSignal.startInit('xxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxx');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.handleNotificationReceived().subscribe(data => this.onPushReceived(data.payload));
this.oneSignal.handleNotificationOpened().subscribe(data => this.onPushOpened(data.notification.payload));
this.oneSignal.endInit();
}
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
private onPushOpened(payload: OSNotificationPayload) {
let alert = this.alertCtrl.create({
title: payload.additionalData.nodename,
subTitle: 'My Note : '+payload.additionalData.title1+' <br/> '+'My Why : '+payload.additionalData.mywhy,
message: payload.body,
buttons: [
{
text: 'Utsett',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Det er utført',
handler: () => {
console.log('oke');
this.responseData = result;
this.nav.setRoot(MynotesPage, {id:payload.additionalData.id});
});
}
}
]
});
alert.present();
}
I can't start intent right from "HandleNotificationOpened" function. Can anybody help me with this problem.

Related

Geolocation is not working on my react native iOS emulator

I used Geolocation in my react native code to get the current position and it is working well on Android. But not work on iOS.
Here is my code
import Geolocation from "#react-native-community/geolocation";
import Geocoder from "react-native-geocoder";
_getCurrentLocation = () => {
Alert.alert(
"Get Location",
"Do you want to update your location?",
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{
text: 'UPDATE', onPress: () => {
Geolocation.setRNConfiguration({ skipPermissionRequests: true, authorizationLevel: "always" });
if (Platform.OS === 'ios') Geolocation.requestAuthorization();
Geolocation.getCurrentPosition(
info => {
const position = { lat: info.coords.latitude, lng: info.coords.longitude }
Geocoder.geocodePosition(position).then(res => {
console.warn(res);
const { updateUserState } = this.props;
updateUserState({ position : position, country : res[0].countryCode, city : res[0].adminArea });
this.setState({ position : position, country : res[0].countryCode, city : res[0].adminArea });
})
.catch(err => {
console.warn(err)
alert(JSON.stringify(err));
})
},
error => {
// alert("Sorry, we cann't get your location now, please check your permission!")
alert(JSON.stringify(error));
console.log(error)
},
{
enableHighAccuracy: false,
timeout: 3000,
// maximumAge: 1000,
},
)
}
}
],
{ cancelable: false }
)
}
I am getting the below error:
PERMISSION_DENIED: 1
POSITION_UNAVAILABLE: 2
TIMEOUT: 3
code: 3
message: "Unable to fetch location within 15.0s."
This is my info.plist:
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires access to you location.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires access to you location.</string>
please set custom latlong in the emulator, Debug -> Location -> Custom
Location and set custom latitude and longitude and run the app agin

Ionic 4 Popover, Alertsheet etc... on iOS scrolls back content and not the popover itself

I hope you all having a great day.
I am facing an issue on iOS with ActionSheets and Popovers, while a popover is appeared, the user can scroll when swiping inside the popover, and it scrolls the back content on which i open the popover from, if i click outside of the popover it closes the popover and it does not let me swipe at all but when i click inside the popover it scrolls the back content of the popover not the popover itself.
here is a video of it:
sorry had no option to upload video, here is a link:
Video of popover/actionsheet
here is code of opening the popover
async openCreateNewFolder(type, folder?) {
const popover = await this.popoverController.create({
component: NewFolderComponent,
componentProps: {
folderId: this.folderId,
parentId: this.parentId,
type,
folder
}
});
popover.onDidDismiss().then((dataReturned) => {
console.log(dataReturned);
if (dataReturned.data !== undefined) {
if (dataReturned.data === 'cancelClicked') {
} else if (dataReturned.data === 'confirmClickedFolder') {
this.deleteFolder(dataReturned.role);
} else if (dataReturned.data === 'confirmClickedFile') {
this.deleteFile(dataReturned.role);
} else if (dataReturned.data === 'newFolderCreated') {
this.getFolders();
}
// this.dataReturned = dataReturned.data;
//alert('Modal Sent Data :'+ dataReturned);
}
});
return await popover.present();
}
here is a code for the actionsheet:
async confirmChangeLanguageDialogue(selectedLanguage) {
let languageClass: any;
if (selectedLanguage === 'English') {
languageClass = 'alertControllerEnglishLanguageIcon';
} else if (selectedLanguage === 'Deutch') {
languageClass = 'alertControllerGermanLanguageIcon';
} else if (selectedLanguage === 'French') {
languageClass = 'alertControllerFrenchLanguageIcon';
} else if (selectedLanguage === 'Italian') {
languageClass = 'alertControllerItalianLanguageIcon';
}
const alert = await this.alertCtrl.create({
header: this.translate.instant('confirm'),
mode: 'ios',
message: this.translate.instant('change_language_confirm_message', {selected_language: selectedLanguage}),
buttons: [
{
text: this.translate.instant('cancel'),
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: this.translate.instant('okay'),
cssClass: languageClass,
handler: () => {
this.requestChangeLanguage(selectedLanguage);
}
}
]
});
await alert.present();
const result = await alert.onDidDismiss();
console.log(result);
}
Any help would be appriciated, thank you.
fix can be found here, check it out:
https://forum.ionicframework.com/t/popover-alertsheet-etc-on-ios-scrolls-back-content-and-not-the-popover-itself/180122

How to add button in push-noitifications to iOS devices with react-native-firebase?

I have a doubt and I am not able to solve the problem of having buttons to perform an action (accept or reject) within a push-notification in iOS with react-native-firebase. For Android I can do it but for iOS I can't find a way to register the action. Next I show how is the code I have.
const notificationListener = () => {
firebase.notifications().onNotification((notification) => {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setSound('default')
.setBody(notification.body)
.setData(notification.data)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setNotificationId(notification.notificationId);
if (Platform.OS === 'android') {
localNotification
.android.setBigText(notification.body)
.android.setSmallIcon('ic_noti_logo_hnc')
.android.setLargeIcon('ic_launcher')
.android.setVisibility(firebase.notifications.Android.Visibility.Public)
.android.setChannelId(CHANNEL_NOTIFICATIONS.CHANNEL_ID)
.android.setPriority(firebase.notifications.Android.Priority.High);
if (isEqual(localNotification.data.set_delay_time, "true")){
// Build an action
const acceptAction = new firebase.notifications.Android.Action('accept_action', 'default', 'Accept');
const rejectAction = new firebase.notifications.Android.Action('reject_action', 'default', 'Reject');
localNotification
.android.addAction(acceptAction)
.android.addAction(rejectAction);
}
} else if (Platform.OS === 'ios') {
localNotification
.ios.setBadge(notification.ios.badge);
}
firebase.notifications().displayNotification(localNotification)
.catch(err => console.error(err));
});
};
What I intend to do is something similar to what you find with Android but the only thing I found the most is IOSNotification.alertAction.
Could someone guide me with this? From already thank you very much!
Nico.
use "react-native-firebase" version 6. You can get the migration information from here.
You can display action buttons using Notifee and handle all the actions click event.
Define actions,
import notifee from '#notifee/react-native';
async function setCategories() {
await notifee.setNotificationCategories([
{
id: 'post',
actions: [
{
id: 'like',
title: 'Like Post',
},
{
id: 'dislike',
title: 'Dislike Post',
},
],
},
]);
}
Assign category to push notification,
import notifee from '#notifee/react-native';
notifee.displayNotification({
title: 'New post from John',
body: 'Hey everyone! Check out my new blog post on my website.',
ios: {
categoryId: 'post',
},
});

don't display notification in ios device when use react-native-fcm

i'm using from react-native-fcm for recieve pushNotification and do all config in this document(https://github.com/evollu/react-native-fcm)
in ios device only recieve notification and call notificationListener that checked by console.log but dont display notification message and alert even test FCM.presentLocalNotification for show local notification still dont show notification
async componentDidMount() {
if (Platform.OS === 'ios') {
try {
const result = await FCM.requestPermissions({ badge: false, sound: true, alert: true });
} catch (e) {
console.error(e);
}
FCM.getFCMToken().then(token => {
if (token !== undefined) {
// this.props.onChangeToken(token);
} else {
console.log('TOKEN (getFCMToken)', 'null');
}
});
// FCM.getAPNSToken().then(token => {
// this.props.onAPNToken(token);
// });
FCM.getInitialNotification().then(notif => {
console.log('INITIAL NOTIFICATION', notif);
});
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
console.log(" >> notificationListener: ", notif)
if (notif.local_notification) return;
FCM.presentLocalNotification({
body: 'tdtydt',
priority: "high",
title: 'notif.fcm.title',
sound: "default",
show_in_foreground: true,
local_notification: true,
icon: "ic_launcher",
status: "400"
});
});
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
console.log('TOKEN (refreshUnsubscribe)', token);
this.props.onChangeToken(token);
});
FCM.enableDirectChannel();
this.channelConnectionListener = FCM.on(FCMEvent.DirectChannelConnectionChanged, (data) => {
console.log(`direct channel connected${data}`);
});
setTimeout(() => {
FCM.isDirectChannelEstablished().then(d => console.log('isDirectChannelEstablished', d));
}, 500);
}

Open pdf in default app using pdfmake

I am able to create pdf in my ionic app and if I run the app in chrome it opens perfectly. However if I install my app on the android device it doesn't open. Below is my code. Can someone please help me if I have to do something extra to open it on device. I want to open it with default pdf application on device.
pdfMake.createPdf(dd).open();
Ok. After banging my head on wall for 3 days I finally found the solution and sharing here so that other people who are facing this issue can get help. I am creating pdf and saving it using cordova file plugin. After successful save I am opening it in default application using cordova file opener plugin. Below is my code.
pdfMake.createPdf(YOUR_DEFINITION_HERE).getBlob(buffer => {
this.file.resolveDirectoryUrl(this.file.externalRootDirectory)
.then(dirEntry => {
this.file.getFile(dirEntry, 'test1.pdf', { create: true })
.then(fileEntry => {
fileEntry.createWriter(writer => {
writer.onwrite = () => {
this.fileOpener.open(fileEntry.toURL(), 'application/pdf')
.then(res => { })
.catch(err => {
const alert = this.alertCtrl.create({ message:
err.message, buttons: ['Ok'] });
alert.present();
});
}
writer.write(buffer);
})
})
.catch(err => {
const alert = this.alertCtrl.create({ message: err, buttons: ['Ok'] });
alert.present();
});
})
.catch(err => {
const alert = this.alertCtrl.create({ message: err, buttons: ['Ok']
});
alert.present();
});
});

Resources