kodeco.com Forums

iOS 10 Screencast: User Notification Management

Learn what notification permissions the user has set & how to interact w/ pending & delivered notifications in the new UserNotifications framework in iOS 10.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4968-ios-10-user-notification-management
1 Like

lol i just noticed the images you put in the app, really cuddly… cacti…

1 Like

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

Hi @silvinaroldan,

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.

Hope that helps


Thanks, the information was really helpful :wink:

1 Like

Hi Sam,

Thanks for your tutorial. I have a question: what is Swift 3 version for this snippet of code ??

let imageURL = Bundle.main.urlForResource(randomImageName, withExtension: "jpg")!
let attachment = try! UNNotificationAttachment(identifier: randomImageName, url: imageURL, options: .none)

Hi @mariam

I’m pretty sure that that snippet of code is already in Swift 3. What problem are you having?


Hi sam,

Thanks for your reply. I got the following error:
Value of type 'Bundle' has no member 'urlForResource'

Also, I tried the below code it worked but when I put image in xcassets it doesn’t work! :frowning: Any help?

if let path = Bundle.main.path(forResource: "SoartAlMulk", ofType: "png")



Apologies, that method has been renamed:

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.

Hope that helps.


Thanks Sam :slight_smile:

I would like to use the image in UNNotificationAttachment, is there a way to do it when the image in asset catalog ?

Best regards,

Hi @mariam

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.

Thank you Sam so much :slight_smile:

1 Like