我想在我的iOS Phonegap应用中收到本地通知.我遵循了很多教程和代码但没有帮助.任何人都可以指导我.
我是swift的新手,我不知道如何实现本地通知我尝试了一些代码,但这并不完全正常,所以任何人都可以帮助在iOS使用中实现本地通知swift?
我刚刚在我的应用中添加了本地通知。仅当应用区域设置regionCode(即Locale.current.regionCode)为“ US”或“ CA”时,才触发这些通知。我对语言环境不感兴趣language。
我还将要编写补充的测试用例,但是一旦我知道如何编写一个测试用例,其他的就自然而然地遵循了。
因此,我的问题是:如何将Locale注入测试中(请参阅参考资料testSuccessfulNotificationDelivery())?
LocalNotificationTests.swift:
class LocalNotificationTests: XCTestCase {
let notification1 = LocalNotification(toTriggerInSeconds: 5)
let notification2 = LocalNotification(toTriggerInSeconds: 6)
// This object manages LocalNotifications
// by building them into UNUserNotifications
// and then scheduling them using UNUserNotificationCenter.
let notificationManager = NotificationManager()
func testSuccessfulNotificationDelivery() {
// setup locale and use it for testing, somehow
let = Locale(identifier: "en_CA")
// The answer to my question would …Run Code Online (Sandbox Code Playgroud) 我使用单一通知,这是我的代码:这是用于注册本地通知>>>
func registerLocal() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("Yay!")
} else {
print("D'oh")
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个函数来安排本地通知>>>
func scheduleLocal() {
registerCategories()
let center = UNUserNotificationCenter.current()
// not required, but useful for testing!
center.removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "good morning"
content.body = "ttt123"
content.categoryIdentifier = "alarm"
content.userInfo = ["customData": "fizzbuzz"]
content.sound = UNNotificationSound.default()
var dateComponents = DateComponents()
dateComponents.hour = 23
dateComponents.minute = 18
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, …Run Code Online (Sandbox Code Playgroud) 我的应用程序处于后台或非活动模式,然后本地通知不起作 我从未收到过关于观看的本地通知.
更新:少于3分钟安排本地通知它工作正常但超过3分钟它不起作用.那么如何解决这个问题呢?
据我所知,我的代码如下.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
// Objective-C
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = [NSString localizedUserNotificationStringForKey:@"Remider!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Your watch is out of range" arguments:nil];
content.sound = [UNNotificationSound defaultSound];
// Time
// 15 min
double timer = 15*60;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time
repeats:NO];
// Actions
UNNotificationAction *snoozeAction = [UNNotificationAction actionWithIdentifier:@"Track"
title:@"Track" options:UNNotificationActionOptionForeground];
// Objective-C
UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"UYLReminderCategory"
actions:@[snoozeAction] intentIdentifiers:@[]
options:UNNotificationCategoryOptionCustomDismissAction];
NSSet *categories = [NSSet setWithObject:category];
// Objective-C …Run Code Online (Sandbox Code Playgroud) 我已经可以显示本地通知,但是在通知下方是否可以显示按钮?
(请参阅所附图片中的“延后”和“关闭”按钮)。

我已经尝试使用 Flutter 实现 Firebase Cloud Messaging,并且在我使用“本地通知”插件显示通知之前我是成功的
我的通知在前台工作正常,但在后台显示此错误:
[错误:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:MissingPluginException(在频道 dexterous.com/flutter/local_notifications 上找不到方法显示的实现)
我使用 Firebase Cloud Messaging 6.0.9、Local Notification 1.2.0+4 和最新的 Flutter
这是我的代码: NotificationHandler
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationHandler{
static final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // make it a static field of the class
static void initNotification()
{
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings, …Run Code Online (Sandbox Code Playgroud) 我对Android中的本地通知有疑问.我正在开发一个应用程序,其中第一部分必须接收我自己的服务器公司的所有会议(我已经实现),第二部分我必须在每次会议前一天通知,但有本地通知.
如何在给定日期安排本地通知?
实际上,我正在开发一个应用程序,可以在日出和日落时间触发本地通知(每天都有所不同,所以不能使用闹钟).另外,我需要脱机使用此功能.
我已经尝试过了:
任何帮助,将不胜感激.:)