Skip to content

Instantly share code, notes, and snippets.

Payal Gupta pgpt10

  • Delhi
Block or report user

Report or block pgpt10

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Notifications10.swift
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void)
{
if response.actionIdentifier == "accept"
{
print("Accept - from Extension")
DispatchQueue.main.async {
completion(.dismissAndForwardAction)
}
}
else
View Notifications9.swift
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
}
View Notifications8.swift
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)
}
View Notifications7.json
{
"aps": {
"alert": {
"title": "Invitation",
"subtitle": "This is a Remote Notification.",
"body": "You are invited."
},
"category": "INVITATION",
"sound": "default",
"content-available": 1,
View Notifications6.swift
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)
View Notofications5.swift
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
{
View Notification4.swift
//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.
}
View Notifications3.swift
//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)
View Notifications3.swift
//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)
View Notifications2.swift
//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.
You can’t perform that action at this time.