Skip to content

Commit

Permalink
Notification example
Browse files Browse the repository at this point in the history
  • Loading branch information
quockhai committed Mar 23, 2018
1 parent 2af9c55 commit 623e4b2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions KQNotification.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = BMX4BQ7A73;
INFOPLIST_FILE = KQNotification/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = vn.khaiquoc.KQNotification;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -304,6 +305,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = BMX4BQ7A73;
INFOPLIST_FILE = KQNotification/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = vn.khaiquoc.KQNotification;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions KQNotification/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

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

KQNotification.shared.registerNotification(withOptions: [.alert, .badge, .sound], completion: nil)

return true
}
}
Expand Down
2 changes: 2 additions & 0 deletions KQNotification/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Notification</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand Down
50 changes: 50 additions & 0 deletions KQNotification/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,64 @@
//

import UIKit
import UserNotifications

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Time Notification
KQNotification.shared.notification(identifier: "notification", title: "KQNotification", body: "Notification after 60s", after: 60, completion: nil)

KQNotification.shared.repeatsNotification(identifier: "repeatNotification", title: "KQNotification", body: "Repeat notification each 300s", after: 300, completion: nil)



let snoozeAction = UNNotificationAction(identifier: "Snooze", title: "Snooze", options: [])
let deleteAction = UNNotificationAction(identifier: "Delete", title: "Delete", options: [.destructive])
KQNotification.shared.actionsNotification(identifier: "actionsNotification", title: "KQNotification", body: "Notification after 100s with actions", actions: [snoozeAction, deleteAction], after: 100, repeats: false, completion: nil)

KQNotification.shared.notificationCenter.delegate = self

/*
// Daily Notification
KQNotification.shared.dailyNotification(identifier: "dailyNotification", title: "KQNotification", body: "Daily notification", date: Date(), completion: nil)
KQNotification.shared.dailyActionsNotification(identifier: "dailyActionsNotification", title: "KQNotification", body: "Daily notification with actions", actions: [snoozeAction, deleteAction], date: Date(), completion: nil)
// Weekly Notification
KQNotification.shared.weeklyNotification(identifier: "weeklyNotification", title: "KQNotification", body: "Weekly notification", date: Date(), completion: nil)
KQNotification.shared.weeklyActionsNotification(identifier: "weeklyActionsNotification", title: "KQNotification", body: "Weekly notification with actions", actions: [snoozeAction, deleteAction], date: Date(), completion: nil)
*/
}
}

extension ViewController: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
switch response.actionIdentifier {
case UNNotificationDefaultActionIdentifier:
print("Default action")

case UNNotificationDismissActionIdentifier:
print("Dismiss action")

case "Snooze":
print("Snooze")

case "Delete":
print("Delete")

default:
print("Unknown action")
break

}

completionHandler()
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
}

0 comments on commit 623e4b2

Please sign in to comment.