Skip to content

Commit

Permalink
add Logger and delete print and nslog
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre jonny cau committed May 24, 2018
1 parent 1e20877 commit 3f98157
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LocalNotifications_Over_iOS10.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "LocalNotifications_Over_iOS10"
s.version = "0.0.14"
s.version = "0.0.15"
s.summary = "Local notifications scheduler in Swift compatible with over iOS10"

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 4 additions & 0 deletions LocalNotifications_Over_iOS10.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
5F11D8D91F7A3D9200A43DF5 /* NotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F11D8D51F7A307700A43DF5 /* NotificationManager.swift */; };
5F340ABD1F7A73DB00520C30 /* NotificationManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F340ABC1F7A73DB00520C30 /* NotificationManagerTest.swift */; };
5F340ABF1F7A73F300520C30 /* NotificationObjectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F340ABE1F7A73F300520C30 /* NotificationObjectTest.swift */; };
5F52FB8820B6B7CC007F2763 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F52FB8720B6B7CC007F2763 /* Logger.swift */; };
5F5B1E9120A636EE00A8B95C /* NotificationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5B1E9020A636EE00A8B95C /* NotificationHelper.swift */; };
5F5B1E9420A637FA00A8B95C /* AttachmentIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5B1E9320A637FA00A8B95C /* AttachmentIdentifier.swift */; };
6F704805F86459ADB92E8BAF /* Pods_LocalNotifications_Over_iOS10.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5848FD45ED2F74325DF0F78 /* Pods_LocalNotifications_Over_iOS10.framework */; };
Expand Down Expand Up @@ -48,6 +49,7 @@
5F340ABC1F7A73DB00520C30 /* NotificationManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManagerTest.swift; sourceTree = "<group>"; };
5F340ABE1F7A73F300520C30 /* NotificationObjectTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationObjectTest.swift; sourceTree = "<group>"; };
5F340AC51F7A810000520C30 /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = "<group>"; };
5F52FB8720B6B7CC007F2763 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
5F5B1E9020A636EE00A8B95C /* NotificationHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationHelper.swift; sourceTree = "<group>"; };
5F5B1E9320A637FA00A8B95C /* AttachmentIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentIdentifier.swift; sourceTree = "<group>"; };
C8E8B39885B3BFD04254F0B7 /* Pods-LocalNotifications_Over_iOS10.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LocalNotifications_Over_iOS10.release.xcconfig"; path = "Pods/Target Support Files/Pods-LocalNotifications_Over_iOS10/Pods-LocalNotifications_Over_iOS10.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -143,6 +145,7 @@
isa = PBXGroup;
children = (
5F5B1E9020A636EE00A8B95C /* NotificationHelper.swift */,
5F52FB8720B6B7CC007F2763 /* Logger.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -349,6 +352,7 @@
53353ACD1D89C7AD0069804D /* ViewController.swift in Sources */,
53353ACB1D89C7AD0069804D /* AppDelegate.swift in Sources */,
5F5B1E9120A636EE00A8B95C /* NotificationHelper.swift in Sources */,
5F52FB8820B6B7CC007F2763 /* Logger.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 5 additions & 4 deletions LocalNotifications_Over_iOS10/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, NotificationManagerDelega

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

Logger.enabled = true
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = NotificationManager.shared()
NotificationManager.shared().setDelegate(self)
Expand Down Expand Up @@ -47,18 +48,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, NotificationManagerDelega
func userNotificationManager(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

if response.notification.request.content.categoryIdentifier == AttachmentIdentifier.shared().image() {
print("categoryIdentifier is Image")
Logger.log(message: "categoryIdentifier is Image", event: .info)

// Retrieve the meeting details.
switch response.actionIdentifier {
case AttachmentIdentifier.shared().share():
print("Share button pressed on notification")
Logger.log(message: "Share button pressed on notification", event: .info)

break

case UNNotificationDefaultActionIdentifier,
UNNotificationDismissActionIdentifier:
print("UNNotificationDefaultActionIdentifier or UNNotificationDismissActionIdentifier")
Logger.log(message: "UNNotificationDefaultActionIdentifier or UNNotificationDismissActionIdentifier", event: .info)
break

default:
Expand All @@ -76,7 +77,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, NotificationManagerDelega
func userNotificationManager(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

if notification.request.content.categoryIdentifier == AttachmentIdentifier.shared().image() {
print("categoryIdentifier is Image")
Logger.log(message: "categoryIdentifier is Image", event: .info)
completionHandler([.sound, .alert])
return

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Logger.swift
// LocalNotifications_Over_iOS10
//
// Created by Pierre jonny cau on 24/05/2018.
// Copyright © 2018 Robots and Pencils. All rights reserved.
//

import Foundation

// Enum for showing the type of Log Types
enum LogEvent: String {
case error = "[‼️]" // error
case info = "[ℹ️]" // info
case debug = "[💬]" // debug
case verbose = "[🔬]" // verbose
case warning = "[⚠️]" // warning
case severe = "[🔥]" // severe
}

class Logger {

static var dateFormat = "yyyy-MM-dd hh:mm:ssSSS"
static var dateFormatter: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = dateFormat
formatter.locale = Locale.current
formatter.timeZone = TimeZone.current
return formatter
}
static var enabled = false //default state

class func log(message: String,
event: LogEvent,
fileName: String = #file,
line: Int = #line,
column: Int = #column,
funcName: String = #function) {
if(!enabled) {
return
}

#if DEBUG
print("\(Date().toString()) \(event.rawValue)[\(sourceFileName(filePath: fileName))]:\(line) \(column) \(funcName) -> \(message)")
#endif
}
private class func sourceFileName(filePath: String) -> String {
let components = filePath.components(separatedBy: "/")
return components.isEmpty ? "" : components.last!
}
}

internal extension Date {
func toString() -> String {
return Logger.dateFormatter.string(from: self as Date)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ public protocol NotificationManagerDelegate: class {
UNUserNotificationCenter.current().add(request) { error in
// Use this block to determine if the notification request was added successfully.
if error == nil {
NSLog("Notification scheduled")
Logger.log(message: "Notification scheduled", event: .info)

} else {
NSLog("Error scheduling notification")
Logger.log(message: "Error scheduling notification", event: .info)
}
}
}
Expand Down Expand Up @@ -257,7 +258,7 @@ public protocol NotificationManagerDelegate: class {
private func customCategory( _ notificationObj:NotificationObject , _ content : UNMutableNotificationContent ) -> UNMutableNotificationContent {

if let name = notificationObj.mediaUrl, let media = notificationObj.media, let url = NotificationHelper.saveImage(name: name,path: notificationObj.mediaPath ) {
print("url is \(url)")
Logger.log(message: "url is \(url)", event: .info)

let attachment = try? UNNotificationAttachment(identifier: media,
url: url,
Expand Down

0 comments on commit 3f98157

Please sign in to comment.