diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5044eb..4f185d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,8 +53,8 @@ jobs: - name: Build and test app run: | pod install - xcodebuild build -workspace PushSDK.xcworkspace -scheme PushSDK -destination 'platform=iOS Simulator,OS=15.5,name=iPhone 13 Pro Max' - xcodebuild test -workspace PushSDK.xcworkspace -scheme PushSDKTests -destination 'platform=iOS Simulator,OS=15.5,name=iPhone 13 Pro Max' + xcodebuild build -workspace PushSDK.xcworkspace -scheme PushSDK -destination 'platform=iOS Simulator,OS=16.0,name=iPhone 13 Pro Max' + xcodebuild test -workspace PushSDK.xcworkspace -scheme PushSDKTests -destination 'platform=iOS Simulator,OS=16.0,name=iPhone 13 Pro Max' - name: Clean up keychain and provisioning profile if: ${{ always() }} diff --git a/PushSDK.podspec b/PushSDK.podspec index 39d71ca..921d69e 100644 --- a/PushSDK.podspec +++ b/PushSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "PushSDK" - s.version = "1.1.1" + s.version = "1.1.2" s.summary = "SDK for sending push messages to iOS devices." s.homepage = "https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS" diff --git a/PushSDK.xcodeproj/xcshareddata/xcschemes/PushSDK.xcscheme b/PushSDK.xcodeproj/xcshareddata/xcschemes/PushSDK.xcscheme index d3ee550..85fbba2 100644 --- a/PushSDK.xcodeproj/xcshareddata/xcschemes/PushSDK.xcscheme +++ b/PushSDK.xcodeproj/xcshareddata/xcschemes/PushSDK.xcscheme @@ -26,7 +26,18 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES" + onlyGenerateCoverageForSpecifiedTargets = "YES"> + + + + diff --git a/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate b/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate index 2f2b355..ccb840d 100644 Binary files a/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate and b/PushSDK.xcworkspace/xcuserdata/o.korniienko.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PushSDK/PushSDKFirebase.swift b/PushSDK/PushSDKFirebase.swift index 74b6b5f..c287d15 100644 --- a/PushSDK/PushSDKFirebase.swift +++ b/PushSDK/PushSDKFirebase.swift @@ -26,6 +26,7 @@ public class PushSDKFirebase: UIResponder, UIApplicationDelegate { @IBOutlet weak var sentNotificationLabel: UILabel? public func registerForPushNotifications() { + UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current() .requestAuthorization(options: [.alert, .sound, .badge]) { [weak self] granted, error in @@ -124,6 +125,8 @@ public class PushSDKFirebase: UIResponder, UIApplicationDelegate { imageUrl: String(parsedMessage.message.image?.url ?? ""), contentTitle: String(parsedMessage.message.title ?? ""), contentBody: String(parsedMessage.message.body ?? ""), + btnText: String(parsedMessage.message.button?.text ?? ""), + btnURL: String(parsedMessage.message.button?.url ?? ""), userInfo: userInfo) } @@ -190,6 +193,19 @@ extension PushSDKFirebase: UNUserNotificationCenterDelegate{ let userInfo = response.notification.request.content.userInfo PushKConstants.logger.debug("userInfo: \(userInfo)") + switch response.actionIdentifier{ + case "pushKNotificationActionId": + let urlS = userInfo["pushKActionButtonURL"] + + if let url = URL(string: urlS as! String){ + UIApplication.shared.open(url) + } + break + + default: + break + } + if let gcmMessageID = userInfo[gcmMessageIDKey] { PushKConstants.logger.debug("gcm message ID: \(gcmMessageID)") } @@ -220,6 +236,8 @@ extension PushSDKFirebase { imageUrl: String(parsedMessage.message.image?.url ?? ""), contentTitle: String(parsedMessage.message.title ?? ""), contentBody: String(parsedMessage.message.body ?? ""), + btnText: String(parsedMessage.message.button?.text ?? ""), + btnURL: String(parsedMessage.message.button?.url ?? ""), userInfo: fdf ?? [:]) } diff --git a/PushSDK/core/Notifications.swift b/PushSDK/core/Notifications.swift index 4d25b90..b8557ff 100644 --- a/PushSDK/core/Notifications.swift +++ b/PushSDK/core/Notifications.swift @@ -17,6 +17,8 @@ class PushNotification { contentTitle: String = "", contentSubtitle: String = "", contentBody: String, + btnText: String, + btnURL: String, userInfo: [AnyHashable: Any] ) { PushKConstants.logger.debug("makePushNotification input: imageUrl: \(imageUrl), timeInterval: \(timeInterval), contentTitle: \(contentTitle), contentSubtitle: \(contentSubtitle), contentBody: \(contentBody)") @@ -34,7 +36,12 @@ class PushNotification { content.subtitle = contentSubtitle } content.sound = UNNotificationSound.default - content.categoryIdentifier = "pushKActionCategory" + if(btnURL != "" && btnText != ""){ + registerNotificationAction(btnText: btnText) + content.categoryIdentifier = "pushKActionCategory" + content.userInfo = ["pushKActionButtonURL" : btnURL] + + } let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval, repeats: false) @@ -91,6 +98,21 @@ class PushNotification { }) } + func registerNotificationAction(btnText: String){ + let acceptAction = UNNotificationAction(identifier: "pushKNotificationActionId", + title: btnText, + options: [UNNotificationActionOptions.foreground]) + + let pushCategory = + UNNotificationCategory(identifier: "pushKActionCategory", + actions: [acceptAction], + intentIdentifiers: [], + hiddenPreviewsBodyPlaceholder: "", + options: .customDismissAction) + + UNUserNotificationCenter.current().setNotificationCategories([pushCategory]) + } + func areNotificationsEnabled(completion:@escaping (Bool)->Swift.Void) { var notificationStatus: Bool = false let current = UNUserNotificationCenter.current() diff --git a/PushSDK/settings/PushConstants.swift b/PushSDK/settings/PushConstants.swift index 06acdd4..93ecb94 100644 --- a/PushSDK/settings/PushConstants.swift +++ b/PushSDK/settings/PushConstants.swift @@ -28,7 +28,7 @@ public struct PushKConstants { let kOSType = "ios" static let serverSdkVersion = "2.3" - static let sdkVersion = "1.1.1" + static let sdkVersion = "1.1.2" static let devOSVersion = UIDevice.current.systemVersion static let deviceType = "\(UIDevice.current.model)" static let deviceType2 = "\(UIDevice.current.batteryLevel)" diff --git a/README.md b/README.md index 4625213..3e3b1ba 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ To open your project run $ open ProjectName.xcworkspace
More about Cocoapods and Podfile here - https://cocoapods.org, https://guides.cocoapods.org/using/the-podfile.html and https://guides.cocoapods.org/using/using-cocoapods.html. ### Add sdk to your project. -Last actual SDK version: 1.1.1
+Last actual SDK version: 1.1.2
To integrate PushSDK to your project with COCOAPODS (https://guides.cocoapods.org/using/the-podfile.html) add the next line in Podfile.
-pod 'PushSDK', :git => 'https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS', :branch => 'gmsapi' +pod 'PushSDK', :git => 'https://github.com/GlobalMessageServices/BCS-GMS-SDK-IOS', :branch => 'main' *** Important ! Before start using SDK, configure firebase project first and create App Id and APNS key. @@ -88,7 +88,7 @@ class ViewController: UIViewController { super.viewDidLoad() //register in notification center NotificationCenter.default.addObserver(self, selector: #selector(onReceiveFromPushServer(_:)), name: .receivePushKData, object: nil) - UNUserNotificationCenter.current().delegate = self + //UNUserNotificationCenter.current().delegate = self } } @@ -114,21 +114,49 @@ extension ViewController: UNUserNotificationCenterDelegate { } } -extension AppDelegate: UNUserNotificationCenterDelegate{ +extension AppDelegate: UNUserNotificationCenterDelegate{ + public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + //If you don't want to show notification when app is open, do something here else and make a return here. completionHandler([.alert, .sound, .badge]) } - + + // For handling tap and user actions public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + + + + let userInfo = response.notification.request.content.userInfo + // handling action button click + switch response.actionIdentifier{ + case "pushKNotificationActionId": + let urlS = userInfo["pushKActionButtonURL"] + + if let url = URL(string: urlS as! String){ + UIApplication.shared.open(url) + } + break + + default: + break + } + completionHandler() } } ``` +### !!! In the code above handling of tap and user actions are going in AppDelegate extension. +In case you want to handlig it in ViewController extension - commit the next line in AppDelegate.swift: +```swift +UNUserNotificationCenter.current().delegate = self +``` +and uncommit the same line in ViewController.swift. + ## An example of registration a device: * Init pPushSDK ```swift