当Apple的官方iOS消息应用程序处于打开状态并位于前台时,来自其他联系人的新消息会触发库存本机iOS通知警报横幅.见下图.
这在App Store的第三方应用程序中是否可行?应用程序处于打开状态且位于前台时,应用程序的本地和/或推送通知?
在测试我的应用时,会收到通知,但不会显示iOS警报用户界面.
但是,这种行为是出现在苹果的官方消息应用程序:

在本地和远程通知编程指南说:
当操作系统提供本地通知或远程通知且目标应用程序未在前台运行时,它可以通过警报,图标标记号或声音向用户显示通知.
如果应用程序在传递通知时在前台运行,则应用程序委托会收到本地或远程通知.
所以是的,我们可以在前台接收通知数据.但我认为无法呈现本机iOS通知警报UI.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// I know we still receive the notification `userInfo` payload in the foreground.
// This question is about displaying the stock iOS notification alert UI.
// Yes, one *could* use a 3rd party toast alert framework.
[self use3rdPartyToastAlertFrameworkFromGithub]
}
Run Code Online (Sandbox Code Playgroud)
然后消息是否使用私有API在前台显示警报?
对于这个问题的目的,请不要提出任何第三方"敬酒",弹出警报在github上或者等我只是有兴趣,如果这可以用做库存,提供原生iOS本地或推送通知提醒用户界面,而你应用程序是开放的,在前台 …
uikit toast apple-push-notifications ios uilocalnotification
现在,AppDelegate和SceneDelegate从SwiftUI删除,你在哪里我把我以前在代码SceneDelegate和AppDelegate,火力地堡配置为前?
所以我目前在我的代码中有这个代码AppDelegate:
我现在应该把这段代码放在哪里?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
return true
}
Run Code Online (Sandbox Code Playgroud) 我是swift的新手,我不知道如何实现本地通知我尝试了一些代码,但这并不完全正常,所以任何人都可以帮助在iOS使用中实现本地通知swift?
是否可以从应用程序显示某种本地通知,即使应用程序未运行(也不在后台)?
例如每日提醒或类似的东西.我知道推送通知是可能的,但它不适合我的应用程序.
当我第一次运行我的应用程序时,模拟器能够在应用程序位于前台时显示通知。
当我重新启动应用程序didReceive notification:(即 iOS 9 中的通知方法)时,将调用willPresent notification(即 iOS 10 中的通知方法),并且当应用程序位于前台时不会显示任何通知。但是,如果应用程序在后台运行,则会显示通知。
我使用以下代码获得通知授权:
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]? = [:]) -> Bool {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .sound]) { (granted, error) in
UNUserNotificationCenter.current().delegate = self
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
我已经实现了 willPresent 通知方法:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) completionHandler(UNNotificationPresentationOptions.alert)
} …Run Code Online (Sandbox Code Playgroud) ios uilocalnotification ios-simulator swift unusernotificationcenter
我正在开发一款可以在中午向您发送通知的应用程序。这个通知应该每天都不同。
我得到了通知本身的工作:
let notificationOptions: UNAuthorizationOptions = [.alert, .sound];
UNUserNotificationCenter.current().requestAuthorization(options: notificationOptions) { (granted, error) in
if !granted {
print("Something went wrong")
} else {
let content = UNMutableNotificationContent()
content.body = getRandomDailyString()
content.sound = UNNotificationSound.default()
let date = DateComponents(hour: 12, minute: 15)
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
let request = UNNotificationRequest(identifier: "Daily String", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
if let error = error {
print(error.localizedDescription)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在发生的情况是调用getRandomDailyString()函数,它返回一个字符串,并设置一个重复通知,该通知确实出现在指定时间,但始终具有相同的内容。
我该如何制作每天提供独特内容的通知?