APNSUtil is makes code simple using apple push notification service

Overview

APNSUtil

Swift CI Status Version License Platform Carthage Compatible

  • APNSUtil makes code simple settings and landing for apple push notification service.

Features

  • Using apple push notification service simply
  • No need write codes for any iOS versions
  • Support chained functional programing

Import

import APNSUtil

Using

Implementation for main view controller

import UIKit
import APNSUtil

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        APNSManager.shared
            .setTypes([.sound, .alert, .badge])             // setting user notification types
            .register()                                     // register to use apns
            .subscribe(self) {                             // subscribe to receive apns payload
                // your payload model with generic
                guard let payload: APNSPayload = $0.payload() else {
                    return
                }

                print("subscribe", $0.isInactive, $0.userInfo, payload)

                if $0.isInactive {
                    // TODO: write code to present viewController on inactive
                } else {
                    // TODO: write code to show toast message on active
                }
            }.begin()   // begin to receive apns payload
    }
}

Implementation for app delegate

import UIKit
import UserNotifications
import APNSUtil

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        APNSManager.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }

    // MARK: - Push Notification

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        APNSManager.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
        // <<your function to register device token on your server>>(APNSInstance.shared.tokenString)
    }
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    }

    // MARK: - Push Notification for iOS 9

    func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
        APNSManager.shared.application(application, didRegister: notificationSettings)
    }
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        APNSManager.shared.application(application, didReceiveRemoteNotification: userInfo)
    }

    // MARK: - Public Methods (UIApplicationDelegate - Local Notification)

    func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
        APNSManager.shared.application(application, didReceive: notification)
    }
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        APNSManager.shared.userNotificationCenter(center, willPresent: notification)
    }
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        APNSManager.shared.userNotificationCenter(center, didReceive: response)
    }
}

Implement your payload model

struct APNSPayload: Decodable {
    let aps: APS?

    // Add properties here you need

    struct APS: Decodable {
        let sound: String?
        let alert: Alert?
    }

    struct Alert: Decodable {
        let body: String?
        let title: String?
    }
}

Using with your payload model as generic

  APNSManager.shared
      .setTypes([.sound, .alert, .badge])
      .register()
      .subscribe(self) {
          guard let payload: APNSPayload = $0.payload() else {
              return
          }

          // write here to process payload model
      }.begin()

Using with raw userInfo

  APNSManager.shared
      .setTypes([.sound, .alert, .badge])
      .register()
      .subscribe(self) {
          let userInfo = $0.userInfo

          // write here to process userInfo
      }.begin()

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.0.0+ is required to build APNSUtil 1.1.5+.

To integrate APNSUtil into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

# Default
target '<Your Target Name>' do
    pod 'APNSUtil', '~> 1.6.0'
end

# for AppExtension
target '<Your Target Name>' do
    pod 'APNSUtil/AppExtension', '~> 1.6.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "pisces/APNSUtil" ~> 1.6.0

Run carthage update to build the framework and drag the built APNSUtil.framework into your Xcode project.

Requirements

iOS Deployment Target 9.0 higher

Author

Steve Kim, [email protected]

License

APNSUtil is available under the MIT license. See the LICENSE file for more info.

You might also like...
Custom notification view
Custom notification view

Custom notification view

Roar - Let's reskin Notification Center

Roar Let's reskin Notification Center. See this blog post. Thanks Big thanks to

ToDoAppCoreData - MVVM + Core Data + Local Notification
ToDoAppCoreData - MVVM + Core Data + Local Notification

ToDo App Features MVVM + Core Data + Local Notification Screen recordings Creadi

FNotify - Notification Library For iOS

FNotify Notification Library For IOS FNotify.mov Requirements: xcode 12+ swift 5

Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS

FocusPlsNoBadges Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS, in a really gross and hacky way. Getting started Build the X

SNPnotificationBar - Notification Bar for ios
SNPnotificationBar - Notification Bar for ios

SNPnotificationBar Screenshot Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements S

A fully customizable library to easily display Animated Toast Messages in iOS using Swift!
A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

CustomToastView-swift A fully customizable library to easily display Animated Toast Messages in iOS using Swift! Preview - All the custom toasts you c

๐ŸšŽ Simple type-safe event bus implementation in swift

๐ŸšŽ RealEventsBus RealEventsBus is a small swift experiment package to implement a basic type-safe event bus mechanism. Some other implementations in G

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

pushHandle OS X app for sending push with Apple Push Notification service (APNs) About This app was created just to allow painless testing of push not

An example implementation of using a native iOS Notification Service Extension (to display images in remote push notification) in Titanium.

Titanium iOS Notification Service Extension An example implementation of using a native iOS Notification Service Extension (to display images in remot

๐Ÿคจ Apple Push Notification service tutorial
๐Ÿคจ Apple Push Notification service tutorial

APNsTutorial-iOS ๐Ÿคจ Apple Push Notification service tutorial ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ

The debug application for Apple Push Notification Service (APNs).
The debug application for Apple Push Notification Service (APNs).

Knuff The debug application for Apple Push Notification Service (APNs). Download the latest version Features Send push notifications to APNS (Apple Pu

OS X and iOS application and framework to play with the Apple Push Notification service (APNs)
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

Swush - macOS Application to play with the Apple Push Notification service (APNs)
Swush - macOS Application to play with the Apple Push Notification service (APNs)

Swush โœจ Description A macOS app to push notifications to APNS with ease. โšก ๐Ÿ’พ Pe

CloudKit, Appleโ€™s remote data storage service, provides a possibility to store app data using usersโ€™ iCloud accounts as a back-end storage service.
CloudKit, Appleโ€™s remote data storage service, provides a possibility to store app data using usersโ€™ iCloud accounts as a back-end storage service.

CloudKit, Appleโ€™s remote data storage service, provides a possibility to store app data using usersโ€™ iCloud accounts as a back-end storage service. He

Approov-service-ios-swift-grpc - Approov service layer for iOS clients using GRPC

Approov Service for GRPC A wrapper for the Approov SDK to enable easy integratio

Warning pushNotification - Using push notification with Firebase Cloud Messaging

์žฌ๋‚œ๋ฌธ์ž ํ‘ธ์‹œ ์•Œ๋ฆผ ๊ตฌํ˜„ 1) ๊ตฌํ˜„ ๊ธฐ๋Šฅ 2) ๊ธฐ๋ณธ ๊ฐœ๋… (1) Remote Notification ๋ถˆ์‹œ์— ๋ฐœ์ƒํ•œ ์—…๋ฐ์ดํŠธ ๋ถˆํŠน์ • ์‹œ๊ฐ„ ์˜ˆ์ธก ๋ถˆ

A simple and attractive AlertView to ask permission to your users for Push Notification.
A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView **to ask permission to your users for Push Notification.** PRESENTATION Ask permission to user for push notification

'Minimalistic Push' is a minimalistic push-up application now built with Flutter.
'Minimalistic Push' is a minimalistic push-up application now built with Flutter.

Minimalistic Push Minimalistic Push is one of the simplest push-up trackers out there. You can track your push-ups in the training mode and see an ove

Releases(1.6.0)
Owner
Steve Kim
Steve Kim
๐Ÿคจ Apple Push Notification service tutorial

APNsTutorial-iOS ?? Apple Push Notification service tutorial ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ

Hyungyu Kim 11 Dec 28, 2022
The debug application for Apple Push Notification Service (APNs).

Knuff The debug application for Apple Push Notification Service (APNs). Download the latest version Features Send push notifications to APNS (Apple Pu

Knuff 5.2k Dec 26, 2022
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

noodlewerk 6.2k Dec 22, 2022
How to Add Local Push Notification With timeInterval & Test On Simulator

Technicalisto How to Add Local Push Notification With timeInterval & Test On Simulator In Project Target ( Signing & Capapilities ) Add Capapility : 1

Aya Baghdadi 0 Jun 24, 2022
Push Notification Registration for iOS

Orbiter Note: This project is no longer being maintained. For most iOS client / server applications, push notifications are negotiated through an inte

Mattt 672 Nov 17, 2022
A Swift Library for Dynamic Island Push Notification.

Push Notification With Dynamic Island Handle Push Notification with Dynamic Island ?? Descreption: Since there is not library for Apple Push Notificat

Amir Diafi 5 Nov 12, 2022
Push notifications allow developers to reach users, even when users aren't actively using an app!

Push notifications allow developers to reach users, even when users aren't actively using an app! With the latest update of iOS Apple provide very useful extensions which are user-friendly. In this tutorial, I am going to share the configuration, set up of Notification with the media attachments like.

MindInventory 16 Mar 3, 2022
Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify English | ็ฎ€ไฝ“ไธญๆ–‡ Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications wit

Chanify 156 Jan 4, 2023
Pushkin is a free open source tool for sending push notifications

Unmaintained This repository is no longer maintained. Pushkin Introduction Pushkin is a free open source tool for sending push notifications. It was d

Nordeus 257 Nov 3, 2022
SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

SystemNotification is a SwiftUI library that lets you mimic the native iOS system notification in your iOS apps.

Daniel Saidi 153 Dec 22, 2022