Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Updated the code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananth committed Mar 1, 2018
1 parent 824add0 commit adbf73c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
18 changes: 8 additions & 10 deletions Source/BMSLocalPush/BMSLocalPushNotification.swift
Expand Up @@ -11,19 +11,16 @@ import UserNotifications

@available(iOS 10.0, *)
class BMSLocalPushNotification: NSObject {

// Optional array of attachments.
open var attachments: String?



// The application badge number. nil means no change. 0 to hide.
open var badge: NSNumber?



// The body of the notification. Use -[NSString localizedUserNotificationStringForKey:arguments:] to provide a string that will be localized at the time that the notification is presented.
open var body: String



// The identifier for a registered UNNotificationCategory that will be used to determine the appropriate actions to display for the notification.
open var categoryIdentifier: String?

Expand Down Expand Up @@ -55,7 +52,7 @@ class BMSLocalPushNotification: NSObject {
self.userInfo = userInfoValue
}

public func showBMSPushNotification(){
public func showBMSPushNotification() {

let notification = UNMutableNotificationContent()
let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
Expand Down Expand Up @@ -106,7 +103,9 @@ class BMSLocalPushNotification: NSObject {
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
}

}

@available(iOS 10.0, *)
extension UNNotificationAttachment {

Expand All @@ -125,8 +124,7 @@ extension UNNotificationAttachment {
} catch let error {
print("error \(error)")
}

return nil
}

}

2 changes: 1 addition & 1 deletion Source/BMSPushClientOptions.swift
Expand Up @@ -81,7 +81,7 @@ public class BMSPushClientOptions : NSObject {
- parameter pushVaribales: a [String:String] values.
*/
public func setPushVariables(pushVaribales variables: [String:String]){
public func setPushVariables(pushVaribales variables: [String:String]) {
self.pushvaribales = variables
}
}
Expand Down
16 changes: 8 additions & 8 deletions Source/BMSPushUtils.swift
Expand Up @@ -45,8 +45,8 @@ internal class BMSPushUtils: NSObject {
class func getPushOptionsNSUserDefaults (key:String) -> String {
var value = ""
if(UserDefaults.standard.value(forKey: key) != nil){
let dataValue = UserDefaults.standard.value(forKey: key) as! [String: String]
let jsonData = try! JSONSerialization.data(withJSONObject: dataValue, options: .prettyPrinted)
let dataValue = UserDefaults.standard.value(forKey: key) as? [String: String]
let jsonData = try! JSONSerialization.data(withJSONObject: dataValue!, options: .prettyPrinted)
value = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)! as String
}
loggerMessage = ("Getting value for NSUserDefaults Key: \(key) and Value: \(value)")
Expand Down Expand Up @@ -99,27 +99,27 @@ internal class BMSPushUtils: NSObject {
let regex = "\\{\\{.*?\\}\\}"
var text = body

guard let gg = UserDefaults.standard.value(forKey: IMFPUSH_VARIABLES) as? [String: String] else { return text }
guard let optionVaribales = UserDefaults.standard.value(forKey: IMFPUSH_VARIABLES) as? [String: String] else { return text }

do {
let regex = try NSRegularExpression(pattern: regex)

let results = regex.matches(in: text,
range: NSRange(text.startIndex..., in: text))
let add = results.flatMap {
let resultMap = results.flatMap {
Range($0.range, in: text).map {
String(text[$0]);
String(text[$0])
}
}

for val in add {
for val in resultMap {
var temp = val
temp = temp.replacingOccurrences(of: "{{", with: "", options: NSString.CompareOptions.literal, range: nil)
temp = temp.replacingOccurrences(of: "}}", with: "", options: NSString.CompareOptions.literal, range: nil)
temp = temp.replacingOccurrences(of: " ", with: "", options: NSString.CompareOptions.literal, range: nil)

if let gad = gg[temp] {
text = text.replacingOccurrences(of: val , with: gad)
if let templateValue = optionVaribales[temp] {
text = text.replacingOccurrences(of: val , with: templateValue)
}
}
return text
Expand Down
Expand Up @@ -10,7 +10,7 @@ import XCTest
@testable import BMSPush

class BMSLocalPushNotificationTest: XCTestCase {

func testInit() {

if #available(iOS 10.0, *) {
Expand Down

0 comments on commit adbf73c

Please sign in to comment.