push-notification
UIApplication.registerForRemoteNotifications() must be called from main thread only
In swift4 You can solve this issue with DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() } Hope this will help…
Silent Push Notification in iOS 7 does not work
This works also and does not play a sound when it arrives: { aps = { “content-available” : 1, sound : “” }; } EDIT People having this problem may want to check out this link. I have been participating in a thread on Apple’s Developer forum that goes over all app states and when … Read more
Get device token for push notification
NOTE: The below solution no longer works on iOS 13+ devices – it will return garbage data. Please use following code instead: + (NSString *)hexadecimalStringFromData:(NSData *)data { NSUInteger dataLength = data.length; if (dataLength == 0) { return nil; } const unsigned char *dataBuffer = (const unsigned char *)data.bytes; NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; … Read more
Swift ios check if remote push notifications are enabled in ios9 and ios10
Apple recommends to use UserNotifications framework instead of shared instances. So, do not forget to import UserNotifications framework. As this framework is new in iOS 10 it’s really only safe to use this code in apps building for iOS10+ let current = UNUserNotificationCenter.current() current.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined { // Notification permission … Read more
Registering for Push Notifications in Xcode 8/Swift 3.0?
Import the UserNotifications framework and add the UNUserNotificationCenterDelegate in AppDelegate.swift Request user permission func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let center = UNUserNotificationCenter.current() center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in // Enable or disable features based on authorization. } application.registerForRemoteNotifications() return true } Getting device token func application(_ application: UIApplication, … Read more
How do iOS Push Notifications work?
Each device can be updated with data using their own unique device tokens. This picture explains everything . .