2016-05-23 14 views
2

私のiPhoneでアプリを実行しました。 (単に私の電話を接続し、私のiPhoneをターゲットとして選んだ。)私はスケジュールされ、iPhone上で完全に時間通りに表示される私のアプリでローカル通知を作成した。ただし、[設定] - > [通知] - > [マイアプリ] - > [ロック画面に表示]がオンになっていても、ロックされた画面には表示されません。ロックされた画面にUILocalNotificationsが表示されない

奇妙なことは、通知センターにも表示されることです。

これはUILocalNotification not showing in the lock screenと似ていますが、回答はありませんでした。

誰かがこれに遭遇しましたか?私はそれがiOSのバグかもしれないと思っています。私は最新のiOS、Xcode、OS Xを使っています。

答えて

3

ロック画面で通知を表示するには、許可を得る必要があります。一度

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 
    let notificationCategory = UIMutableUserNotificationCategory() 
    let categories = Set<UIUserNotificationCategory>(arrayLiteral: notificationCategory) 
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories) 
    application.registerUserNotificationSettings(settings) 
    return true 
} 

スウィフト3

まず、次にdidFinishLaunchingWithOptions

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound , .badge]) {(accepted, error) in 
      if !accepted { 
       print("Notification access denied.") 
      } 
     } 
+0

'セットでのコードを追加しimport UserNotificationsを追加Appdelegate.swiftのコードを見て(配列リテラル:) 'イニシャライザは直接使用するためのものではなく、配列リテラルで使用することを意図しています。 '[notificationCategory]'だけ書くことができます。とにかくスウィフト3のために今はほとんど無関係です:) – jtbandes

関連する問題