Android 反应本机-在特定时间间隔后显示通知-iOS
我有一个场景,我需要在每个特定时间段(通常为3天)后使用本地通知而不是基于互联网的推送通知提醒用户Android 反应本机-在特定时间间隔后显示通知-iOS,android,ios,notifications,react-native-ios,background-fetch,Android,Ios,Notifications,React Native Ios,Background Fetch,我有一个场景,我需要在每个特定时间段(通常为3天)后使用本地通知而不是基于互联网的推送通知提醒用户 我使用的是react native,并且有专门使用native Android的背景。我正在寻找类似AlarmService或SyncAdapter for iOS的东西,可以是本机的,也可以是基于本机的。我最终制作了自己的简单模块,用于处理计划的本地通知。。。下面是我用来安排通知的一个片段 UNUserNotificationCenter *center = [UNUserNotificat
我使用的是react native,并且有专门使用native Android的背景。我正在寻找类似AlarmService或SyncAdapter for iOS的东西,可以是本机的,也可以是基于本机的。我最终制作了自己的简单模块,用于处理计划的本地通知。。。下面是我用来安排通知的一个片段
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
//check notification permission
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
// Notifications not allowed
}else{
// show notificaiton
RCTLogInfo(@"Showing Notification with title: %@", title);
//set notification content
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = title;
content.body = body;
content.sound = [UNNotificationSound defaultSound];
//add timer in ms
NSTimeInterval timeInterval = interval;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
//set identifier with any string
NSString *identifier = id;
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
//request for scheduling notification
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if(error != nil){
RCTLogInfo(@"Something went wrong: %@", error);
};
}];
}
}];
这是我的schedular的精简版本,实际代码也支持添加图像附件,但由于这篇特定的文章只是关于安排它们,因此我不得不放弃一些功能。我最终制作了自己的简单模块来处理计划的本地通知。。。下面是我用来安排通知的一个片段
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
//check notification permission
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
// Notifications not allowed
}else{
// show notificaiton
RCTLogInfo(@"Showing Notification with title: %@", title);
//set notification content
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = title;
content.body = body;
content.sound = [UNNotificationSound defaultSound];
//add timer in ms
NSTimeInterval timeInterval = interval;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
//set identifier with any string
NSString *identifier = id;
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
//request for scheduling notification
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if(error != nil){
RCTLogInfo(@"Something went wrong: %@", error);
};
}];
}
}];
这是我的schedular的精简版本,实际代码也支持添加图像附件,但由于这篇特定的文章只是关于安排它们,因此我不得不放弃一些功能。我也希望这样做。你找到解决方法了吗?我制作了自己的模块来处理它们,检查下面的答案,希望它能帮助我,我也希望能这样做。你们找到解决方案了吗?我制作了自己的模块来处理它们,检查下面的答案,希望能有所帮助