Reputation: 4336
UILocalNotification
has an alertTitle
property but it doesn't work. Whatever title you give to a notification, it shows my apps name instead. If you check iCalendar's event alert, they are not showing app's name.
P.S: It has nothing to do with UIAlertView, because I am talking about it effect in background state.
Upvotes: 3
Views: 1064
Reputation: 2494
I have checked it with Xcode 7
and Swift 2
and it is working for me:
Following is my code in ViewController
file for initialization and assign properties to 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)
At the same time in AppDelegate.swift
, i was written following code:
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()
}
}
I hope above information will work for you.
In image -> "Reminder" is Title of my LocalNotification and notification body is "Message Body"
Upvotes: 1