Learn what notification permissions the user has set & how to interact w/ pending & delivered notifications in the new UserNotifications framework in iOS 10.
Hi, I have a question, UNUserNotificationCenter.current().getPendingNotificationRequests works only for notifications you schedule locally on the user’s device, right? because with push I don’t have a request
Yes, you’re correct: that method will only return local notifications. Remote notifications are delivered immediately as they’re sent, so there would never be any pending remote notifications.
However, a UNNotification object for a remote notification does have a UNNotificationRequest object on its request property, but this is synthesised from the information received from the APNS server.
let imageURL = Bundle.main.url(forResource: randomImageName, withExtension: "jpg")
should do the trick.
The reason you can’t get hold of the path for that image in the asset library is because it’s compiled into the asset catalog itself, and thus isn’t accessible in the app bundle directly.
If you just need the image then you can use the following constructor:
if let image = UIImage(named: "SoartAlMulk") { ... }
Alternatively, you can actually use image literals inside Xcode—which allows you to choose an image inline. Behind the scenes this uses the UIImage(imageLiteralResourceName:) initialiser.
Although it it is possible to get hold of the URL of an item in the asset catalog, I don’t think it is supported behaviour. I would therefore suggest that you put images that you want to use for user notifications directly into the bundle instead.
I’m not 100% sure on this though, so it might be worth doing some more searching around. However, I don’t see that there are any significant problems in using the bundle directly for this purpose.
Well I put it directly into the bundle. And I searched a lot all what I found they do it like this. But I afraid it’s not a good approach that why I asked.