푸시 알림을 보내고 응용 프로그램이 포 그라운드에있는 경우 willPresent
이 호출됩니다. didReceive
은 호출되지 않습니다. 응용 프로그램이 백그라운드에서 푸시 알림을 받으면 경고가 표시되지만 응용 프로그램에서는 didReceive
또는 willPresent
을 호출하지 않습니다.UNUserNotificationCenter가 수신되지 않았습니다.
프로젝트> 기능에서 백그라운드 모드 Location updates
및 Remote notifications
을 확인했습니다. 위치 업데이트는 관련없는 코드 용입니다.
푸시 알림을 사용하도록 설정했습니다. 그들은 잘 받고 있습니다.
내가 내 AppDelegate
에 UNUserNotificationCenter
알림 물건을 구현 한, 아래 참조 : 왜 didReceive
하지
import UserNotifications
...
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
registerForPushNotifications(application: application)
...
}
// MARK: - Push Notifications
func registerForPushNotifications(application: UIApplication) {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.delegate = self
notificationCenter.requestAuthorization(options: [.badge, .sound, .alert], completionHandler: {(granted, error) in
if (granted)
{
UIApplication.shared.registerForRemoteNotifications()
}
else{
//Do stuff if unsuccessful...
print("Unsuccessful in registering for push notifications")
}
})
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//convert the deviceToken to a string
let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", arguments: [$0]) }.joined()
let ud = UserDefaults.standard
ud.set(deviceTokenString, forKey: "deviceToken")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//Handle the notification
print("User Info = ",notification.request.content.userInfo)
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
//handle the notification
print("Push notification: ",response.notification.request.content.userInfo)
... code to import the notification data into Core Data.
completionHandler()
}
...
}
어떤 아이디어를 호출되고?
이것은 수신 된 푸시 알림 :
[AnyHashable("aps"): {
alert = "[name] has added you as a friend.";
category = "NEWS_CATEGORY";
"related_user_id" = 55;
sound = default;
type = "friend_request";
}]
아이폰 OS 10.1, 스위프트 3. 알림 배너를 눌러 경우 willPresent
메소드가 호출됩니다
당신이 우는 소리 IOS 10.0에서 테스트 (알림을 밀어을, 아래로 스 와이프 등)를 호출 할 것인가? –
@jigneshVadadoriya no, ios 10.1 – toast