Unit testing iOS 10 notifications

前端 未结 3 493
太阳男子
太阳男子 2021-02-05 13:13

In my app I wish to assert that notifications have been added in the correct format. I\'d normally do this with dependency injection, but I can\'t think of a way to test the new

3条回答
  •  日久生厌
    2021-02-05 13:29

    You can utilize UNUserNotificationCenter, then setValue on the returned settings

    UNUserNotificationCenter.current().getNotificationSettings(completionHandler: { settings in
        let status: UNAuthorizationStatus = .authorized
        settings.setValue(status.rawValue, forKey: "authorizationStatus")
        completionHandler(settings)
    })
    

提交回复
热议问题