Skip to content

OS X app for sending push with Apple Push Notification service (APNs)

License

Notifications You must be signed in to change notification settings

khorbushko/Antumbra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo


Swift ICONKit-license verions

🇺🇦

OS X app for sending push with Apple Push Notification service (APNs) over HTTP/2 API.

About

This app was created just to allow painless testing of push notifications.

It's completely open source and any improvements are welcome.

screenshot

The whole story with app started quite ago. Here my blog-post about first attemp. On this blog I will try to cover the most interesting features and functionality related to the app soon.

Features

App supports all basic ways of sending push notifications.

Main features are:

  • Auth with p8 key
  • Auth with p12 cert
  • Auth with keychain
  • Custom push paylod
  • Payload JSON validation
  • Predefined payloads
  • Full customization of push
  • Build in hints
  • Multiply sessions
  • Session persistants
  • History with detailed info
  • Inspection of request with option to use curl for p8 auth
  • Rich failure description
  • Light/Dark mode
  • Written in Swift

In progress:

  • Create reusable sp for APNS
  • Support generate terminal command
  • Live push preview

Quick guide

Configre apple developer account:

  • generate certificate sign request on mac (Keychain->File->Request certificate sign identity)

  • Log in to Apple's Dev Center
  • Go to the Provisioning Portal or Certificates, Identifiers & Profiles
  • Create app identifier
  • Add certificate for push (sandbox and/or production)
  • Create p8 Key at Apple's Dev Center to use the app (optional)

In the project u need to allow required capabilities:

Then in u'r project App:

assuming u use SwiftUI

  1. declare UIApplicationDelegateAdaptor
@main
struct AuthentificatorApp: App {

  @UIApplicationDelegateAdaptor
  private var appDelegate: AppDelegate
  
  ....
  1. handle callbacks
final class AppDelegate: NSObject, UIApplicationDelegate {

  private let pushHandle: PushTokenHandle = .init()

  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  ) -> Bool {
    pushHandle.performStartConfig()
    pushHandle.handleIfAppOpenedWithNotificationInfo(launchOptions: launchOptions)

    return true
  }

  func application(
    _ application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
  ) {
    pushHandle.subscribeUsing(pushToken: deviceToken)
  }

  func application(
    _ application: UIApplication,
    didFailToRegisterForRemoteNotificationsWithError error: Error
  ) {
  // handle error
  }
}

implemntation of PushHandle:

final public class PushTokenHandle: NSObject {

  func performStartConfig() {
    UNUserNotificationCenter.current().delegate = self
  }

  func subscribeUsing(pushToken: Data) {
    let deviceToken = pushToken.hexString
  }
}

extension PushTokenHandle: UNUserNotificationCenterDelegate {
  public func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions
    ) -> Void) {
    let userInfo = notification.request.content.userInfo
    completionHandler([.banner, .badge, .sound])
  }

  public func userNotificationCenter(
    _ center: UNUserNotificationCenter,
    didReceive response: UNNotificationResponse,
    withCompletionHandler completionHandler: @escaping () -> Void
  ) {
    let userInfo = response.notification.request.content.userInfo

    handlePushTap(userInfo)
    completionHandler()
  }
}

extension PushTokenHandle {

  func handleIfAppOpenedWithNotificationInfo(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
    if let remotePushObject = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] {
      // parse object and send
    }
  }

  func handlePushTap(_ response: [AnyHashable: Any]) {
    let application = UIApplication.shared
    if application.applicationState == .active {
      debugPrint("user tapped the notification bar when the app is in foreground")
    }

    if application.applicationState == .inactive {
      debugPrint("user tapped the notification bar when the app is in background")
    }
  }
}
  1. convert data to tokenString:
public extension Data {

  var hexString: String {
    let parts = self.map { data in String(format: "%02.2hhx", data) }
    let value = parts.joined()
    return value
  }
}

More info about APNS here and here

License

MIT licensed.

Thanks to

Contact

Have a question or an issue about Antumbra? Create an issue!

If you would like to contribute - just create a pull request.


About

OS X app for sending push with Apple Push Notification service (APNs)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published