2015-10-13 100 views
3

UILocalNotification有一個alertTitle屬性,但它不起作用。無論您給予通知的標題是什麼,它都會顯示我的應用程序名稱。如果您檢查iCalendar的事件警報,它們不會顯示應用程序的名稱。UILocalNotification的alertTitle屬性不起作用

P.S:它與UIAlertView無關,因爲我正在談論它在後臺狀態的影響。

+0

它將從IOS版本8.2上運行。 –

+0

我正在使用iOS版本9,它不會更改。 –

+0

標題字符串應該很短,通常只有幾個字來描述通知的原因。 –

回答

1

我與Xcode 7Swift 2檢查,它爲我工作:

以下是我在ViewController文件初始化代碼,並在AppDelegate.swift分配屬性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) 

同時,我寫了下面的代碼:

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和通知的身體的標題是「消息正文」

+1

如果應用程序處於後臺狀態,則不會調用didReceiveLocalNotification。我們無法改變標題。嘗試在應用程序處於後臺狀態時執行此操作。 –