1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Got iOS build to work

This commit is contained in:
Laurent Cozic
2020-10-14 23:53:14 +01:00
parent dc6d7c00e0
commit b5811d7f7c
11 changed files with 986 additions and 74 deletions

View File

@ -1,84 +1,85 @@
// import { Notification } from 'lib/models/Alarm';
// import Logger from 'lib/Logger';
// const PushNotificationIOS = require('@react-native-community/push-notification-ios').default;
import { Notification } from 'lib/models/Alarm';
import Logger from 'lib/Logger';
const PushNotificationIOS = require('@react-native-community/push-notification-ios').default;
// export default class AlarmServiceDriver {
export default class AlarmServiceDriver {
// private hasPermission_:boolean = null;
// private inAppNotificationHandler_:any = null;
private hasPermission_:boolean = null;
private inAppNotificationHandler_:any = null;
private logger_:Logger;
// constructor(logger:Logger) {
// this.logger_ = logger;
// PushNotificationIOS.addEventListener('localNotification', (instance:any) => {
// if (!this.inAppNotificationHandler_) return;
constructor(logger:Logger) {
this.logger_ = logger;
PushNotificationIOS.addEventListener('localNotification', (instance:any) => {
if (!this.inAppNotificationHandler_) return;
// if (!instance || !instance._data || !instance._data.id) {
// console.warn('PushNotificationIOS.addEventListener: Did not receive a proper notification instance');
// return;
// }
if (!instance || !instance._data || !instance._data.id) {
this.logger_.warn('PushNotificationIOS.addEventListener: Did not receive a proper notification instance');
return;
}
// const id = instance._data.id;
// this.inAppNotificationHandler_(id);
// });
// }
const id = instance._data.id;
this.inAppNotificationHandler_(id);
});
}
// hasPersistentNotifications() {
// return true;
// }
hasPersistentNotifications() {
return true;
}
// notificationIsSet() {
// throw new Error('Available only for non-persistent alarms');
// }
notificationIsSet() {
throw new Error('Available only for non-persistent alarms');
}
// setInAppNotificationHandler(v:any) {
// this.inAppNotificationHandler_ = v;
// }
setInAppNotificationHandler(v:any) {
this.inAppNotificationHandler_ = v;
}
// async hasPermissions(perm:any = null) {
// if (perm !== null) return perm.alert && perm.badge && perm.sound;
async hasPermissions(perm:any = null) {
if (perm !== null) return perm.alert && perm.badge && perm.sound;
// if (this.hasPermission_ !== null) return this.hasPermission_;
if (this.hasPermission_ !== null) return this.hasPermission_;
// return new Promise((resolve) => {
// PushNotificationIOS.checkPermissions(async (perm:any) => {
// const ok = await this.hasPermissions(perm);
// this.hasPermission_ = ok;
// resolve(ok);
// });
// });
// }
return new Promise((resolve) => {
PushNotificationIOS.checkPermissions(async (perm:any) => {
const ok = await this.hasPermissions(perm);
this.hasPermission_ = ok;
resolve(ok);
});
});
}
// async requestPermissions() {
// const options:any = {
// alert: 1,
// badge: 1,
// sound: 1,
// };
// const newPerm = await PushNotificationIOS.requestPermissions(options);
// this.hasPermission_ = null;
// return this.hasPermissions(newPerm);
// }
async requestPermissions() {
const options:any = {
alert: 1,
badge: 1,
sound: 1,
};
const newPerm = await PushNotificationIOS.requestPermissions(options);
this.hasPermission_ = null;
return this.hasPermissions(newPerm);
}
// async clearNotification(id:any) {
// PushNotificationIOS.cancelLocalNotifications({ id: `${id}` });
// }
async clearNotification(id:number) {
PushNotificationIOS.cancelLocalNotifications({ id: `${id}` });
}
// async scheduleNotification(notification:Notification) {
// if (!(await this.hasPermissions())) {
// const ok = await this.requestPermissions();
// if (!ok) return;
// }
async scheduleNotification(notification:Notification) {
if (!(await this.hasPermissions())) {
const ok = await this.requestPermissions();
if (!ok) return;
}
// // ID must be a string and userInfo must be supplied otherwise cancel won't work
// const iosNotification:any = {
// id: `${notification.id}`,
// alertTitle: notification.title,
// fireDate: notification.date.toISOString(),
// userInfo: { id: `${notification.id}` },
// };
// ID must be a string and userInfo must be supplied otherwise cancel won't work
const iosNotification:any = {
id: `${notification.id}`,
alertTitle: notification.title,
fireDate: notification.date.toISOString(),
userInfo: { id: `${notification.id}` },
};
// if ('body' in notification) iosNotification.alertBody = notification.body;
if ('body' in notification) iosNotification.alertBody = notification.body;
// PushNotificationIOS.scheduleLocalNotification(iosNotification);
// }
// }
PushNotificationIOS.scheduleLocalNotification(iosNotification);
}
}