Latest 1.0.6
Homepage https://github.com/minyingwu/SwiftNotification
License MIT
Platforms ios 10.0
Authors

CI Status
Version
License
Platform

Contents

Requirements

  • iOS 10.0+
  • Xcode 8.0+
  • Swift 3.0+

Installation

SwiftNotification is available through CocoaPods. To install
it, simply add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'SwiftNotification'
end

Then, run the following command:

$ pod install

Usage

To manage your custom notification, and you can add some codes like following

AppDelegate

/**
 AppDelegate.
 */
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: 
                     [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        /**
        Setup SwiftNotification
         */

        // Set your center such as UNUserNotificationCenter.current()
        NotificationSettings.center = '<Your Current Center>'

        // Set your custom center delegate such as UNUserNotificationCenterDelegate()
        NotificationSettings.delegate = '<Your Current Center Delegate>'

        return true
}

Then, create one function to handle APNS/FCM json result

fileprivate var info: NotificationInfo?
func buildNotification(data: [AnyHashable: Any]) {
        // First, save data to model NotificationInfo
        setNotificationInfo(data)
        if let info = info {
            // Second, create NotificationBuilderHelper instance by receive data and your custom notification id
            let buildHelper = NotificationBuilderHelper(withMessage: data, notificationId: info.getNotificationId())

            // Third, connect to  extension NotificationBuilderDelegate 
            buildHelper.delegate = self

            // Fourth, create notification with optional actions and show the banner
            let actionsContext: [ActionContext] = [("Action1Title", .foreground)]
            buildHelper.createNotification(with: .defaultSound, add: actionsContext)?.show()
        }else {
            print("Never initialize model of notificationInfo")
        }
}

NotificationBuilderDelegate

In your using NotificationBuilderHelper class must inherit NotificationBuilderDelegate

public protocol NotificationBuilderDelegate: class {
    func getNotificationInfo() -> NotificationInfo

    func getNotificationIdentityDic() -> Dictionary<String, NotificationIdentity>?
}

image

Optional API

NotificationBuilderHelper

  • updateMsgData:

    Adding or updating notificationContent userinfo by your new dictionary before calling
    createNotification or createNotificationByCustom

  • createNotificationByCustom:

    You can call createNotificationByCustom and take advantage of custom getNotificationIdentityDic
    to define your all kinds of necessary notification identities

Author

minyingwu, [email protected]

License

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

Latest podspec

{
    "name": "SwiftNotification",
    "version": "1.0.6",
    "summary": "A simple SDK to create different local notifications after iOS 10.0",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/minyingwu/SwiftNotification",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "minyingwu": "[email protected]"
    },
    "source": {
        "git": "https://github.com/minyingwu/SwiftNotification.git",
        "tag": "1.0.6"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "SwiftNotification/Classes/**/*",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3"
    }
}

Pin It on Pinterest

Share This