gpt4 book ai didi

ios - UILocalNotification 的 alertTitle 属性不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:42 25 4
gpt4 key购买 nike

UILocalNotification 有一个 alertTitle 属性,但它不起作用。无论您给通知起什么标题,它都会显示我的应用程序名称。如果您查看 iCalendar 的事件提醒,它们不会显示应用的名称。

P.S:与UIAlertView无关,因为我说的是后台状态下的效果。

最佳答案

我已经用 Xcode 7Swift 2 检查了它,它对我有用:

以下是我在 ViewController 文件中的代码,用于初始化并将属性分配给 UILocalNotification()

   let localNoti : UILocalNotification = UILocalNotification()
localNoti.fireDate = //fireDate
localNoti.alertTitle = //Your title will goes here
localNoti.alertBody = "alert body for local notification"


UIApplication.sharedApplication().scheduleLocalNotification(localNoti)

同时在AppDelegate.swift中,我写了如下代码:

    func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification){
let state: UIApplicationState = application.applicationState
if state == UIApplicationState.Active{

// Here i have created an AlertView to display local notification, Which will give title to LocalNotification

let alertView = UIAlertView(title: notification.alertTitle, message: notification.alertBody, delegate: nil, cancelButtonTitle: "OK")
alertView.show()
}
}

希望以上信息对您有用。

enter image description here在图片中 -> “提醒”是我的 LocalNotification 的标题,通知正文是“消息正文”

关于ios - UILocalNotification 的 alertTitle 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33100751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com