Created
          July 2, 2017 15:53 
        
      - 
      
- 
        Save hashier/cc09d1c5bcfc99d4e283b34b2aa8e826 to your computer and use it in GitHub Desktop. 
    Just +1 the badge and add '[modified]' to the title of 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
    
  
  
    
  | Connected to APNS | |
| array(1) { | |
| ["aps"]=> | |
| array(4) { | |
| ["alert"]=> | |
| string(13) "badge testing" | |
| ["sound"]=> | |
| string(7) "default" | |
| ["badge"]=> | |
| int(98) | |
| ["mutable-content"]=> | |
| int(1) | |
| } | |
| } | |
| Message successfully delivered | |
| 119 | 
  
    
      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
    
  
  
    
  | // | |
| // NotificationService.swift | |
| // quickTest | |
| // | |
| // Created by Christopher Loessl on 2017-07-02. | |
| // Copyright © 2017. All rights reserved. | |
| // | |
| import UserNotifications | |
| class NotificationService: UNNotificationServiceExtension { | |
| var contentHandler: ((UNNotificationContent) -> Void)? | |
| var bestAttemptContent: UNMutableNotificationContent? | |
| 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.title = "\(bestAttemptContent.title) [modified]" | |
| bestAttemptContent.badge = NSNumber(value: bestAttemptContent.badge!.intValue + 1) | |
| contentHandler(bestAttemptContent) | |
| } | |
| } | |
| override func serviceExtensionTimeWillExpire() { | |
| if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { | |
| bestAttemptContent.badge = 42 | |
| contentHandler(bestAttemptContent) | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment