This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) | |
{ | |
if response.actionIdentifier == "accept" | |
{ | |
print("Accept - from Extension") | |
DispatchQueue.main.async { | |
completion(.dismissAndForwardAction) | |
} | |
} | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func didReceive(_ notification: UNNotification) | |
{ | |
self.titleLabel?.text = notification.request.content.title | |
self.subTitleLabel?.text = notification.request.content.subtitle | |
self.bodyLabel?.text = notification.request.content.body | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) | |
{ | |
self.contentHandler = contentHandler | |
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) | |
if let bestAttemptContent = bestAttemptContent | |
{ | |
// Modify the notification content here... | |
bestAttemptContent.body = "Address: Sea Shells Apartments, Mumbai" //Here..!!! | |
contentHandler(bestAttemptContent) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"aps": { | |
"alert": { | |
"title": "Invitation", | |
"subtitle": "This is a Remote Notification.", | |
"body": "You are invited." | |
}, | |
"category": "INVITATION", | |
"sound": "default", | |
"content-available": 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) | |
{ | |
let tokenParts = deviceToken.map { data -> String in | |
return String(format: "%02.2hhx", data) | |
} | |
let token = tokenParts.joined() | |
print("Device Token: \(token)") | |
} | |
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) | |
{ | |
switch response.notification.request.content.categoryIdentifier | |
{ | |
case "GENERAL": | |
break | |
case "INVITATION": | |
switch response.actionIdentifier | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Here you decide whether to silently handle the notification or still alert the user. | |
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) | |
{ | |
//Write you app specific code here | |
completionHandler([.alert, .sound]) //execute the provided completion handler block with the delivery option (if any) that you want the system to use. If you do not specify any options, the system silences the notification. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Notification Content | |
let content = UNMutableNotificationContent() | |
content.title = "Invitation" | |
content.subtitle = "This is a Local Notification." | |
content.body = "You are invited." | |
content.categoryIdentifier = "INVITATION" | |
content.sound = UNNotificationSound.default() | |
//Notification Trigger - when the notification should be fired | |
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Notification Content | |
let content = UNMutableNotificationContent() | |
content.title = "Invitation" | |
content.subtitle = "This is a Local Notification." | |
content.body = "You are invited." | |
content.categoryIdentifier = "INVITATION" | |
content.sound = UNNotificationSound.default() | |
//Notification Trigger - when the notification should be fired | |
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Actions | |
let remindLaterAction = UNNotificationAction(identifier: "remindLater", title: "Remind me later", options: UNNotificationActionOptions(rawValue: 0)) | |
let acceptAction = UNNotificationAction(identifier: "accept", title: "Accept", options: .foreground) | |
let declineAction = UNNotificationAction(identifier: "decline", title: "Decline", options: .destructive) | |
let commentAction = UNTextInputNotificationAction(identifier: "comment", title: "Comment", options: .authenticationRequired, textInputButtonTitle: "Send", textInputPlaceholder: "Share your thoughts..") | |
//Category | |
let invitationCategory = UNNotificationCategory(identifier: "INVITATION", actions: [remindLaterAction, acceptAction, declineAction, commentAction], intentIdentifiers: [], options: UNNotificationCategoryOptions(rawValue: 0)) | |
//Register the app’s notification types and the custom actions that they support. |