2017-09-21 12 views
0

カテゴリに登録しようとしていますが、何らかの理由で私のiPhoneでそれを行うことはできませんが、シミュレータ上で動作しますか?私は登録するために次のコードを使用して、次に私が購読しているカテゴリを確認するためにチェックします。私のiPhoneに私のアプリを実行している間、私がチェックしたとき、それは0言うと、私はシミュレータ上でチェックするときには、1通知カテゴリの登録方法を教えてください。

 let snoozeAction = UNNotificationAction(identifier: "SNOOZE_ACTION", 
              title: "Snooze", 
              options: .foreground) 
    let expiredCategory = UNNotificationCategory(identifier: "TIMER_EXPIRED", 
               actions: [snoozeAction], 
               intentIdentifiers: [], 
               options: UNNotificationCategoryOptions(rawValue: 0)) 
    let center = UNUserNotificationCenter.current() 
    center.setNotificationCategories([expiredCategory]) 

は、私は、私は何が起こっているのかの手掛かりを持っていない

UNUserNotificationCenter.current().getNotificationCategories { categories in 
      print("These are the categories\(categories.count)") 
      print(categories.description) 
     } 

に確認してくださいと言います!

答えて

0

これを試してみると、私のために働いています。

func notificationSetup() 
{ 
    if #available(iOS 10.0, *) 
    { 
    let center = UNUserNotificationCenter.current() 
     center.delegate = self 
     center.requestAuthorization(options: [.alert,.badge,.sound]) { granted,error in 
     if (error == nil) { 
     UIApplication.shared.registerForRemoteNotifications() 
     } 
    } 
    let snoozeAction = UNNotificationAction(identifier: "SNOOZE_ACTION", title: "Snooze", options: [.foreground, .authenticationRequired]) 
    let categoryOptions = UNNotificationCategoryOptions(rawValue: 0) 
    let expiredCategory = UNNotificationCategory(identifier: "TIMER_EXPIRED", actions: [snoozeAction], intentIdentifiers: [], options: categoryOptions) 
    let categories = Set([expiredCategory]) 
    center.setNotificationCategories(categories) 

    } 
} 
+0

ねえ答えるためのおかげで、これは本物のiPhone上で動作していません。これは、仕事やシミュレータでしたが...それはまったく意味がありません。 – user7097242

+0

私は同じことをすべてやっていて、かなりうまく動作しているので、もっとコードを表示できますか? –

関連する問題