From 3608dc7ed1fe8afcb6fdca6922b882a30779f45d Mon Sep 17 00:00:00 2001 From: Ognjen Ristanovic Date: Tue, 5 Sep 2023 16:15:25 +0200 Subject: [PATCH] WIP cordova sdk 17 --- config_sample.xml | 4 +- package.json | 4 +- scripts/create_sample.sh | 2 - urbanairship-cordova/package.json | 2 +- urbanairship-cordova/plugin.xml | 15 +- .../src/android/build-extras.gradle | 2 +- .../src/ios/AirshipCordova.swift | 596 ++++++++++++++++++ .../src/ios/UACordovaPluginManager.h | 5 - .../src/ios/UACordovaPluginManager.m | 21 +- urbanairship-cordova/src/ios/UAirshipPlugin.h | 8 - urbanairship-cordova/src/ios/UAirshipPlugin.m | 550 ++++++---------- urbanairship-cordova/www/AirshipActions.mjs | 59 ++ urbanairship-cordova/www/AirshipAnalytics.mjs | 97 +++ urbanairship-cordova/www/AirshipChannel.mjs | 110 ++++ urbanairship-cordova/www/AirshipContact.mjs | 96 +++ urbanairship-cordova/www/AirshipLocale.mjs | 77 +++ .../www/AirshipMessageCenter.mjs | 153 +++++ .../www/AirshipPreferenceCenter.mjs | 107 ++++ .../www/AirshipPrivacyManager.mjs | 160 +++++ urbanairship-cordova/www/AirshipPush.mjs | 382 +++++++++++ urbanairship-cordova/www/AirshipRoot.mjs | 123 ++++ urbanairship-hms-cordova/package.json | 2 +- urbanairship-hms-cordova/plugin.xml | 4 +- .../src/android/build-extras.gradle | 2 +- 24 files changed, 2199 insertions(+), 382 deletions(-) create mode 100644 urbanairship-cordova/src/ios/AirshipCordova.swift create mode 100644 urbanairship-cordova/www/AirshipActions.mjs create mode 100644 urbanairship-cordova/www/AirshipAnalytics.mjs create mode 100644 urbanairship-cordova/www/AirshipChannel.mjs create mode 100644 urbanairship-cordova/www/AirshipContact.mjs create mode 100644 urbanairship-cordova/www/AirshipLocale.mjs create mode 100644 urbanairship-cordova/www/AirshipMessageCenter.mjs create mode 100644 urbanairship-cordova/www/AirshipPreferenceCenter.mjs create mode 100644 urbanairship-cordova/www/AirshipPrivacyManager.mjs create mode 100644 urbanairship-cordova/www/AirshipPush.mjs create mode 100644 urbanairship-cordova/www/AirshipRoot.mjs diff --git a/config_sample.xml b/config_sample.xml index 98a51eb6..53ce060e 100644 --- a/config_sample.xml +++ b/config_sample.xml @@ -46,8 +46,8 @@ - - + + diff --git a/package.json b/package.json index 0b4e41df..2f0ce474 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,7 @@ "build-ios": "cd ../cordova-sample/test; cordova build ios", "run-android": "cd ../cordova-sample/test; cordova run android", "run-ios": "cd ../cordova-sample/test; cordova run ios", - "add-accengage-module": "cd ../cordova-sample/test; cordova plugin add ../../urbanairship-cordova/urbanairship-accengage-cordova", - "remove-accengage-module": "cd ../cordova-sample/test; cordova plugin rm urbanairship-accengage-cordova", "add-hms-module": "cd ../cordova-sample/test; cordova plugin add ../../urbanairship-cordova/urbanairship-hms-cordova", "remove-hms-module": "cd ../cordova-sample/test; cordova plugin rm urbanairship-hms-cordova" } -} \ No newline at end of file +} diff --git a/scripts/create_sample.sh b/scripts/create_sample.sh index 53bc5db6..7c1a8b99 100755 --- a/scripts/create_sample.sh +++ b/scripts/create_sample.sh @@ -5,7 +5,6 @@ set -euxo pipefail cd `dirname "${0}"`/../ ROOT_PATH="$(pwd)" CORDOVA_AIRSHIP_MODULE="$ROOT_PATH/urbanairship-cordova" -CORDOVA_AIRSHIP_ACCENGAGE_MODULE="$ROOT_PATH/urbanairship-accengage-cordova" CORDOVA_AIRSHIP_HMS_MODULE="$ROOT_PATH/urbanairship-hms-cordova" cd - @@ -38,7 +37,6 @@ npm install cordova@$CORDOVA_VERSION # add the plugins npx cordova plugin add $CORDOVA_AIRSHIP_MODULE -npx cordova plugin add $CORDOVA_AIRSHIP_ACCENGAGE_MODULE npx cordova plugin add $CORDOVA_AIRSHIP_HMS_MODULE # copy config and example files diff --git a/urbanairship-cordova/package.json b/urbanairship-cordova/package.json index 0bd7dbf1..166fe11a 100644 --- a/urbanairship-cordova/package.json +++ b/urbanairship-cordova/package.json @@ -1,6 +1,6 @@ { "name": "urbanairship-cordova", - "version": "14.10.1", + "version": "15.0.0", "description": "Urban Airship Cordova plugin", "cordova": { "id": "urbanairship-cordova", diff --git a/urbanairship-cordova/plugin.xml b/urbanairship-cordova/plugin.xml index d33a1b61..48d450b9 100644 --- a/urbanairship-cordova/plugin.xml +++ b/urbanairship-cordova/plugin.xml @@ -1,6 +1,6 @@ @@ -40,7 +40,7 @@ + android:value="15.0.0"/> + + @@ -145,7 +147,7 @@ - 14.10.1 + 15.0.0 @@ -191,6 +193,7 @@ + @@ -198,11 +201,7 @@ - - - - - + diff --git a/urbanairship-cordova/src/android/build-extras.gradle b/urbanairship-cordova/src/android/build-extras.gradle index fa447b75..4a399edb 100644 --- a/urbanairship-cordova/src/android/build-extras.gradle +++ b/urbanairship-cordova/src/android/build-extras.gradle @@ -1,5 +1,5 @@ dependencies { - def airshipVersion = "16.11.1" + def airshipVersion = "17.1.0" implementation "com.urbanairship.android:urbanairship-fcm:$airshipVersion" implementation "com.urbanairship.android:urbanairship-message-center:$airshipVersion" implementation "com.urbanairship.android:urbanairship-automation:$airshipVersion" diff --git a/urbanairship-cordova/src/ios/AirshipCordova.swift b/urbanairship-cordova/src/ios/AirshipCordova.swift new file mode 100644 index 00000000..5e2cd1bc --- /dev/null +++ b/urbanairship-cordova/src/ios/AirshipCordova.swift @@ -0,0 +1,596 @@ +/* Copyright Airship and Contributors */ + +import Foundation +import AirshipKit +import AirshipFrameworkProxy +//import React + +@objc +public class AirshipCordova: NSObject { + + @objc + public static let pendingEventsEventName = "com.airship.pending_events" + + @objc + public static let overridePresentationOptionsEventName = "com.airship.ios.override_presentation_options" + + + var lock = AirshipLock() + var pendingPresentationRequests: [String: PresentationOptionsOverridesRequest] = [:] + + @objc + public var overridePresentationOptionsEnabled: Bool = false { + didSet { + if (!overridePresentationOptionsEnabled) { + lock.sync { + self.pendingPresentationRequests.values.forEach { request in + request.result(options: nil) + } + self.pendingPresentationRequests.removeAll() + } + } + } + } + + public static var proxy: AirshipProxy { + AirshipProxy.shared + } + + public static let version: String = "15.2.2" + + private let eventNotifier = EventNotifier() + + @objc + public static let shared: AirshipCordova = AirshipCordova() + + @objc + public func setNotifier(_ notifier: ((String, [String: Any]) -> Void)?) { + Task { + if let notifier = notifier { + await eventNotifier.setNotifier({ + notifier(AirshipReactNative.pendingEventsEventName, [:]) + }) + + if await AirshipProxyEventEmitter.shared.hasAnyEvents() { + await eventNotifier.notifyPendingEvents() + } + + + AirshipProxy.shared.push.presentationOptionOverrides = { request in + guard self.overridePresentationOptionsEnabled else { + request.result(options: nil) + return + } + + let requestID = UUID().uuidString + self.lock.sync { + self.pendingPresentationRequests[requestID] = request + } + notifier( + AirshipReactNative.overridePresentationOptionsEventName, + [ + "pushPayload": request.pushPayload, + "requestId": requestID + ] + ) + } + } else { + await eventNotifier.setNotifier(nil) + AirshipProxy.shared.push.presentationOptionOverrides = nil + + lock.sync { + self.pendingPresentationRequests.values.forEach { request in + request.result(options: nil) + } + self.pendingPresentationRequests.removeAll() + } + } + } + } + + @objc + public func presentationOptionOverridesResult(requestID: String, presentationOptions: [String]?) { + lock.sync { + pendingPresentationRequests[requestID]?.result(optionNames: presentationOptions) + pendingPresentationRequests[requestID] = nil + } + } + + + @objc + @MainActor + public func onLoad( + launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) { + AirshipProxy.shared.delegate = self + try? AirshipProxy.shared.attemptTakeOff(launchOptions: launchOptions) + + Task { + let stream = await AirshipProxyEventEmitter.shared.pendingEventTypeAdded + for await _ in stream { + await self.eventNotifier.notifyPendingEvents() + } + } + } + + @objc + public func onListenerAdded(eventName: String) { + guard let type = try? AirshipProxyEventType.fromReactName(eventName) else { + return + } + + Task { + if (await AirshipProxyEventEmitter.shared.hasEvent(type: type)) { + await self.eventNotifier.notifyPendingEvents() + } + } + } + + @objc + public func takePendingEvents(eventName: String) async -> [Any] { + guard let type = try? AirshipProxyEventType.fromReactName(eventName) else { + return [] + } + + return await AirshipProxyEventEmitter.shared.takePendingEvents( + type: type + ).map { $0.body } + } + + + @objc + @MainActor + public func attemptTakeOff( + launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) { + try? AirshipProxy.shared.attemptTakeOff(launchOptions: launchOptions) + } +} + +// Airship +public extension AirshipCordova { + @objc + @MainActor + func takeOff( + json: Any, + launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.takeOff( + json: json, + launchOptions: launchOptions + ) + ) + } + + @objc + func isFlying() -> Bool { + return Airship.isFlying + } + +} + +// Channel +@objc +public extension AirshipCordova { + + @objc + func channelAddTags(_ tags: [String]) throws { + return try AirshipProxy.shared.channel.addTags(tags) + } + + @objc + func channelRemoveTag(_ tag: String) throws { + return try AirshipProxy.shared.channel.removeTags([tag]) + } + + @objc + func channelEnableChannelCreation() throws -> Void { + try AirshipProxy.shared.channel.enableChannelCreation() + } + + @objc + func channelGetTags() throws -> [String] { + return try AirshipProxy.shared.channel.getTags() + } + + @objc + func channelGetSubscriptionLists() async throws -> [String] { + return try await AirshipProxy.shared.channel.getSubscriptionLists() + } + + @objc + func channelGetChannelIdOrEmpty() throws -> String { + return try AirshipProxy.shared.channel.getChannelId() ?? "" + } + + @objc + func channelEditTagGroups(json: Any) throws { + try AirshipProxy.shared.channel.editTagGroups(json: json) + } + + @objc + func channelEditAttributes(json: Any) throws { + try AirshipProxy.shared.channel.editAttributes(json: json) + } + + @objc + func channelEditSubscriptionLists(json: Any) throws { + try AirshipProxy.shared.channel.editSubscriptionLists(json: json) + } +} + +// Push +@objc +public extension AirshipCordova { + @objc + func pushSetUserNotificationsEnabled( + _ enabled: Bool + ) throws -> Void { + try AirshipProxy.shared.push.setUserNotificationsEnabled(enabled) + } + + @objc + func pushIsUserNotificationsEnabled() throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.push.isUserNotificationsEnabled() + ) + } + + @objc + func pushEnableUserNotifications() async throws -> Bool { + return try await AirshipProxy.shared.push.enableUserPushNotifications() + } + + @objc + func pushGetRegistrationTokenOrEmpty() throws -> String { + return try AirshipProxy.shared.push.getRegistrationToken() ?? "" + } + + @objc + func pushSetNotificationOptions( + names:[String] + ) throws { + try AirshipProxy.shared.push.setNotificationOptions(names: names) + } + + @objc + func pushSetForegroundPresentationOptions( + names:[String] + ) throws { + try AirshipProxy.shared.push.setForegroundPresentationOptions( + names: names + ) + } + + @objc + func pushGetNotificationStatus() async throws -> [String: Any] { + return try await AirshipProxy.shared.push.getNotificationStatus() + } + + @objc + func pushSetAutobadgeEnabled(_ enabled: Bool) throws { + try AirshipProxy.shared.push.setAutobadgeEnabled(enabled) + } + + @objc + func pushIsAutobadgeEnabled() throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.push.isAutobadgeEnabled() + ) + } + + @objc + @MainActor + func pushSetBadgeNumber(_ badgeNumber: Double) throws { + try AirshipProxy.shared.push.setBadgeNumber(Int(badgeNumber)) + } + + @objc + @MainActor + func pushGetBadgeNumber() throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.push.getBadgeNumber() + ) + } + + @objc + func pushGetAuthorizedNotificationStatus() throws -> String { + return try AirshipProxy.shared.push.getAuthroizedNotificationStatus() + } + + @objc + func pushGetAuthorizedNotificationSettings() throws -> [String] { + return try AirshipProxy.shared.push.getAuthorizedNotificationSettings() + } + + @objc + func pushClearNotifications() { + AirshipProxy.shared.push.clearNotifications() + } + + @objc + func pushClearNotification(_ identifier: String) { + AirshipProxy.shared.push.clearNotification(identifier) + } + + @objc + func pushGetActiveNotifications() async -> [[String: Any]] { + return await AirshipProxy.shared.push.getActiveNotifications() + } +} + +// Actions +@objc +public extension AirshipCordova { + func actionsRun(actionName: String, actionValue: Any?) async throws-> Any? { + return try await AirshipProxy.shared.action.runAction( + actionName, + value: try AirshipJSON.wrap(actionValue) + ) + } +} + +// Analytics +@objc +public extension AirshipCordova { + + func analyticsTrackScreen(_ screen: String?) throws { + try AirshipProxy.shared.analytics.trackScreen(screen) + } + + func analyticsAssociateIdentifier(_ identifier: String?, key: String) throws { + try AirshipProxy.shared.analytics.associateIdentifier( + identifier: identifier, + key: key + ) + } +} + +// Contact +@objc +public extension AirshipCordova { + + @objc + func contactIdentify(_ namedUser: String?) throws { + try AirshipProxy.shared.contact.identify(namedUser ?? "") + } + + @objc + func contactReset() throws { + try AirshipProxy.shared.contact.reset() + } + + @objc + func contactGetNamedUserIdOrEmtpy() async throws -> String { + return try await AirshipProxy.shared.contact.getNamedUser() ?? "" + } + + @objc + func contactGetSubscriptionLists() async throws -> [String: [String]] { + return try await AirshipProxy.shared.contact.getSubscriptionLists() + } + + @objc + func contactEditTagGroups(json: Any) throws { + try AirshipProxy.shared.contact.editTagGroups(json: json) + } + + @objc + func contactEditAttributes(json: Any) throws { + try AirshipProxy.shared.contact.editAttributes(json: json) + } + + @objc + func contactEditSubscriptionLists(json: Any) throws { + try AirshipProxy.shared.contact.editSubscriptionLists(json: json) + } +} + +// InApp +@objc +public extension AirshipCordova { + + func inAppIsPaused() throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.inApp.isPaused() + ) + } + + func inAppSetPaused(_ paused: Bool) throws { + try AirshipProxy.shared.inApp.setPaused(paused) + } + + func inAppSetDisplayInterval(milliseconds: Double) throws { + try AirshipProxy.shared.inApp.setDisplayInterval(Int(milliseconds)) + } + + func inAppGetDisplayInterval() throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.inApp.getDisplayInterval() + ) + } +} + +// Locale +@objc +public extension AirshipCordova { + @objc + func localeSetLocaleOverride(localeIdentifier: String?) throws { + try AirshipProxy.shared.locale.setCurrentLocale(localeIdentifier) + } + + @objc + func localeClearLocaleOverride() throws { + try AirshipProxy.shared.locale.clearLocale() + } + + @objc + func localeGetLocale() throws -> String { + return try AirshipProxy.shared.locale.getCurrentLocale() + } +} + +// Message Center +@objc +public extension AirshipCordova { + @objc + func messageCenterGetUnreadCount() async throws -> Double { + return try await Double(AirshipProxy.shared.messageCenter.getUnreadCount()) + } + + @objc + func messageCenterGetMessages() async throws -> [Any] { + return try await AirshipProxy.shared.messageCenter.getMessagesJSON() + } + + @objc + func messageCenterMarkMessageRead(messageId: String) async throws { + try await AirshipProxy.shared.messageCenter.markMessageRead( + messageID: messageId + ) + } + + @objc + func messageCenterDeleteMessage(messageId: String) async throws { + try await AirshipProxy.shared.messageCenter.deleteMessage( + messageID: messageId + ) + } + + @objc + func messageCenterDismiss() throws { + return try AirshipProxy.shared.messageCenter.dismiss() + } + + @objc + func messageCenterDisplay(messageId: String?) throws { + try AirshipProxy.shared.messageCenter.display(messageID: messageId) + } + + @objc + func messageCenterRefresh() async throws { + try await AirshipProxy.shared.messageCenter.refresh() + } + + @objc + func messageCenterSetAutoLaunchDefaultMessageCenter(autoLaunch: Bool) { + AirshipProxy.shared.messageCenter.setAutoLaunchDefaultMessageCenter(autoLaunch) + } +} + +// Preference Center +@objc +public extension AirshipCordova { + @objc + func preferenceCenterDisplay(preferenceCenterId: String) throws { + try AirshipProxy.shared.preferenceCenter.displayPreferenceCenter( + preferenceCenterID: preferenceCenterId + ) + } + + @objc + func preferenceCenterGetConfig(preferenceCenterId: String) async throws -> Any { + return try await AirshipProxy.shared.preferenceCenter.getPreferenceCenterConfig( + preferenceCenterID: preferenceCenterId + ) + } + + @objc + func preferenceCenterAutoLaunchDefaultPreferenceCenter( + preferenceCenterId: String, + autoLaunch: Bool + ) { + AirshipProxy.shared.preferenceCenter.setAutoLaunchPreferenceCenter( + autoLaunch, + preferenceCenterID: preferenceCenterId + ) + } +} + +// Privacy Manager +@objc +public extension AirshipCordova { + @objc + func privacyManagerSetEnabledFeatures(features: [String]) throws { + try AirshipProxy.shared.privacyManager.setEnabled(featureNames: features) + } + + @objc + func privacyManagerGetEnabledFeatures() throws -> [String] { + return try AirshipProxy.shared.privacyManager.getEnabledNames() + } + + @objc + func privacyManagerEnableFeature(features: [String]) throws { + try AirshipProxy.shared.privacyManager.enable(featureNames: features) + } + + @objc + func privacyManagerDisableFeature(features: [String]) throws { + try AirshipProxy.shared.privacyManager.disable(featureNames: features) + } + + @objc + func privacyManagerIsFeatureEnabled(features: [String]) throws -> NSNumber { + return try NSNumber( + value: AirshipProxy.shared.privacyManager.isEnabled(featuresNames: features) + ) + } +} + + +extension AirshipCordova: AirshipProxyDelegate { + public func migrateData(store: ProxyStore) { + ProxyDataMigrator().migrateData(store: store) + } + + public func loadDefaultConfig() -> AirshipConfig { + let config = AirshipConfig.default() + config.requireInitialRemoteConfigEnabled = true + return config + } + + public func onAirshipReady() { + Airship.analytics.registerSDKExtension( + .reactNative, + version: AirshipReactNative.version + ) + } +} + + +private actor EventNotifier { + private var notifier: (() -> Void)? + func setNotifier(_ notifier: (() -> Void)?) { + self.notifier = notifier + } + + func notifyPendingEvents() { + self.notifier?() + } +} + + +extension AirshipProxyEventType { + private static let nameMap: [String: AirshipProxyEventType] = [ + "com.airship.deep_link": .deepLinkReceived, + "com.airship.channel_created": .channelCreated, + "com.airship.push_token_received": .pushTokenReceived, + "com.airship.message_center_updated": .messageCenterUpdated, + "com.airship.display_message_center": .displayMessageCenter, + "com.airship.display_preference_center": .displayPreferenceCenter, + "com.airship.notification_response": .notificationResponseReceived, + "com.airship.push_received": .pushReceived, + "com.airship.notification_status_changed": .notificationStatusChanged, + "com.airship.authorized_notification_settings_changed": .authorizedNotificationSettingsChanged + ] + + public static func fromReactName(_ name: String) throws -> AirshipProxyEventType { + guard let type = AirshipProxyEventType.nameMap[name] else { + throw AirshipErrors.error("Invalid type: \(self)") + } + + return type + } +} diff --git a/urbanairship-cordova/src/ios/UACordovaPluginManager.h b/urbanairship-cordova/src/ios/UACordovaPluginManager.h index b5b8952e..be99ddcf 100644 --- a/urbanairship-cordova/src/ios/UACordovaPluginManager.h +++ b/urbanairship-cordova/src/ios/UACordovaPluginManager.h @@ -2,11 +2,6 @@ #import -#if __has_include("AirshipLib.h") -#import "AirshipLib.h" -#else -@import AirshipKit; -#endif NS_ASSUME_NONNULL_BEGIN diff --git a/urbanairship-cordova/src/ios/UACordovaPluginManager.m b/urbanairship-cordova/src/ios/UACordovaPluginManager.m index 615842c5..6726f01a 100644 --- a/urbanairship-cordova/src/ios/UACordovaPluginManager.m +++ b/urbanairship-cordova/src/ios/UACordovaPluginManager.m @@ -2,11 +2,10 @@ #import "UACordovaPluginManager.h" -#if __has_include("AirshipLib.h") -#import "AirshipLib.h" -#import "AirshipMessageCenterLib.h" +#if __has_include() +#import #else -@import AirshipKit; +#import "cordova_airship-Swift.h" #endif #import "UACordovaEvent.h" @@ -58,16 +57,18 @@ - (void)load { object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { - [self attemptTakeOffWithLaunchOptions:note.userInfo]; + [AirshipCordova.shared attemptTakeOffWithLaunchOptions:note.userInfo]; }]; } - (void)dealloc { + /* [UAirship push].pushNotificationDelegate = nil; [UAirship push].registrationDelegate = nil; [UAMessageCenter shared].displayDelegate = nil; [UAPreferenceCenter shared].openDelegate = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; + */ } - (instancetype)initWithDefaultConfig:(NSDictionary *)defaultConfig { @@ -85,6 +86,7 @@ + (instancetype)pluginManagerWithDefaultConfig:(NSDictionary *)defaultConfig { return [[UACordovaPluginManager alloc] initWithDefaultConfig:defaultConfig]; } +/* - (void)attemptTakeOff { [self attemptTakeOffWithLaunchOptions:nil]; } @@ -112,11 +114,13 @@ - (void)attemptTakeOffWithLaunchOptions:(NSDictionary *)launchOptions { [self loadCustomNotificationCategories]; + /* [UAirship push].pushNotificationDelegate = self; [UAirship push].registrationDelegate = self; [UAMessageCenter shared].displayDelegate = self; [UAirship shared].deepLinkDelegate = self; [UAPreferenceCenter shared].openDelegate = self; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inboxUpdated) @@ -137,7 +141,8 @@ - (void)attemptTakeOffWithLaunchOptions:(NSDictionary *)launchOptions { self.isAirshipReady = YES; } - +*/ +/* - (void)loadCustomNotificationCategories { NSString *categoriesPath = [[NSBundle mainBundle] pathForResource:CategoriesPlistPath ofType:@"plist"]; NSSet *customNotificationCategories = [UANotificationCategories createCategoriesFromFile:categoriesPath]; @@ -148,7 +153,8 @@ - (void)loadCustomNotificationCategories { [[UAirship push] updateRegistration]; } } - + */ +/* - (UAConfig *)createAirshipConfig { UAConfig *airshipConfig = [UAConfig config]; airshipConfig.productionAppKey = [self configValueForKey:ProductionAppKeyConfigKey]; @@ -188,6 +194,7 @@ - (UAConfig *)createAirshipConfig { return airshipConfig; } + */ - (void)registerCordovaPluginVersion { NSString *version = [NSBundle mainBundle].infoDictionary[UACordovaPluginVersionKey] ?: @"0.0.0"; diff --git a/urbanairship-cordova/src/ios/UAirshipPlugin.h b/urbanairship-cordova/src/ios/UAirshipPlugin.h index 8fbfe64a..91edda44 100644 --- a/urbanairship-cordova/src/ios/UAirshipPlugin.h +++ b/urbanairship-cordova/src/ios/UAirshipPlugin.h @@ -3,14 +3,6 @@ #import #import -#if __has_include("AirshipLib.h") -#import "AirshipLib.h" -#import "AirshipMessageCenterLib.h" -#import "AirshipAutomationLib.h" -#else -@import AirshipKit; -#endif - /** * The Urban Airship Cordova plugin. */ diff --git a/urbanairship-cordova/src/ios/UAirshipPlugin.m b/urbanairship-cordova/src/ios/UAirshipPlugin.m index f1cff661..538b60d2 100644 --- a/urbanairship-cordova/src/ios/UAirshipPlugin.m +++ b/urbanairship-cordova/src/ios/UAirshipPlugin.m @@ -1,18 +1,16 @@ /* Copyright Urban Airship and Contributors */ -#import "UAirshipPlugin.h" -#import "UACordovaPluginManager.h" -#import "UACordovaPushEvent.h" -#import "UAMessageViewController.h" -#if __has_include("AirshipLib.h") -#import "AirshipLib.h" -#import "AirshipMessageCenterLib.h" -#import "AirshipAutomationLib.h" +#if __has_include() +#import #else -@import AirshipKit; +#import "cordova_airship-Swift.h" #endif +#import "UAirshipPlugin.h" +#import "UACordovaPluginManager.h" +#import "UACordovaPushEvent.h" + NSString *const PreferenceCenterIdKey = @"id"; NSString *const PreferenceCenterSectionsKey = @"sections"; NSString *const PreferenceCenterDisplayKey = @"display"; @@ -32,7 +30,6 @@ @interface UAirshipPlugin() @property (nonatomic, copy) NSString *listenerCallbackID; -@property (nonatomic, weak) UAMessageViewController *messageViewController; @property (nonatomic, strong) UACordovaPluginManager *pluginManager; @property (nonatomic, weak) UAInAppMessageHTMLAdapter *htmlAdapter; @property (nonatomic, assign) BOOL factoryBlockAssigned; @@ -175,32 +172,34 @@ - (void)takeOff:(CDVInvokedUrlCommand *)command { UA_LDEBUG(@"Performing takeOff with args: %@", args); NSDictionary *config = [args objectAtIndex:0]; + if (!config[@"production"] || !config[@"development"]) { completionHandler(CDVCommandStatus_ERROR, @"Invalid config"); return; } + if (self.pluginManager.isAirshipReady) { UA_LINFO(@"TakeOff already called. Config will be applied next app start."); + completionHandler(CDVCommandStatus_OK, nil); } - NSDictionary *development = config[@"development"]; - [self.pluginManager setDevelopmentAppKey:development[@"appKey"] appSecret:development[@"appSecret"]]; - - NSDictionary *production = config[@"production"]; - [self.pluginManager setProductionAppKey:production[@"appKey"] appSecret:production[@"appSecret"]]; - - [self.pluginManager setCloudSite:config[@"site"]]; - [self.pluginManager setMessageCenterStyleFile:config[@"messageCenterStyleConfig"]]; - if (!self.pluginManager.isAirshipReady) { - [self.pluginManager attemptTakeOff]; + NSError *error; + id result = [AirshipReactNative.shared takeOffWithJson:config + launchOptions:nil + error:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } + if (!self.pluginManager.isAirshipReady) { completionHandler(CDVCommandStatus_ERROR, @"Invalid config. Airship unable to takeOff."); } } - completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -218,12 +217,12 @@ - (void)setNotificationTypes:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setNotificationTypes called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - UANotificationOptions types = [[args objectAtIndex:0] intValue]; + UANotificationOptions types = [[args objectAtIndex:0]]; + [AirshipCordova.shared pushSetNotificationOptions:types]; + UA_LDEBUG(@"Setting notification types: %ld", (long)types); - [UAirship push].notificationOptions = types; - [[UAirship push] updateRegistration]; - + completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -232,10 +231,12 @@ - (void)setPresentationOptions:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setPresentationOptions called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - UNNotificationPresentationOptions options = [[args objectAtIndex:0] intValue]; + UNNotificationPresentationOptions options = [[args objectAtIndex:0]]; UA_LDEBUG(@"Setting presentation options types: %ld", (long)options); - [self.pluginManager setPresentationOptions:(NSUInteger)options]; + + [AirshipCordova.shared pushSetForegroundPresentationOptions:options]; + completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -248,10 +249,7 @@ - (void)setUserNotificationsEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setUserNotificationsEnabled set to:%@", enabled ? @"true" : @"false"); - [UAirship push].userPushNotificationsEnabled = enabled; - - //forces a reregistration - [[UAirship push] updateRegistration]; + [AirshipCordova.shared pushSetUserNotificationsEnabled:enabled]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -261,12 +259,13 @@ - (void)enableUserNotifications:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"enableUserNotifications called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAirship push] enableUserPushNotifications:^(BOOL success) { + [AirshipCordova.shared pushEnableUserNotifications:^(BOOL success) { completionHandler(CDVCommandStatus_OK, [NSNumber numberWithBool:success]); - }]; + }]; }]; } + - (void)setAssociatedIdentifier:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setAssociatedIdentifier called with command arguments: %@", command.arguments); @@ -274,49 +273,21 @@ - (void)setAssociatedIdentifier:(CDVInvokedUrlCommand *)command { NSString *key = [args objectAtIndex:0]; NSString *identifier = [args objectAtIndex:1]; - UAAssociatedIdentifiers *identifiers = [UAirship.analytics currentAssociatedDeviceIdentifiers]; - [identifiers setIdentifier:identifier forKey:key]; - [UAirship.analytics associateDeviceIdentifiers:identifiers]; - - completionHandler(CDVCommandStatus_OK, nil); - }]; -} - -- (void)setAnalyticsEnabled:(CDVInvokedUrlCommand *)command { - UA_LTRACE(@"setAnalyticsEnabled called with command arguments: %@", command.arguments); - - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - NSNumber *value = [args objectAtIndex:0]; - BOOL enabled = [value boolValue]; - if (enabled) { - [[UAirship shared].privacyManager enableFeatures:UAFeaturesAnalytics]; - } else { - [[UAirship shared].privacyManager disableFeatures:UAFeaturesAnalytics]; - } + [AirshipCordova.shared analyticsAssociateIdentifier:identifier key:key]; completionHandler(CDVCommandStatus_OK, nil); }]; } -- (void)isAnalyticsEnabled:(CDVInvokedUrlCommand *)command { - UA_LTRACE(@"isAnalyticsEnabled called with command arguments: %@", command.arguments); - - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - BOOL enabled = [[UAirship shared].privacyManager isEnabled:UAFeaturesAnalytics]; - - completionHandler(CDVCommandStatus_OK, [NSNumber numberWithBool:enabled]); - }]; -} - - (void)isUserNotificationsEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"isUserNotificationsEnabled called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - BOOL enabled = [UAirship push].userPushNotificationsEnabled; - completionHandler(CDVCommandStatus_OK, [NSNumber numberWithBool:enabled]); + NSNumber *enabled = [AirshipCordova.shared pushIsUserNotificationsEnabled]; + completionHandler(CDVCommandStatus_OK, enabled); }]; } - +/* - (void)isQuietTimeEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"isQuietTimeEnabled called with command arguments: %@", command.arguments); @@ -353,7 +324,7 @@ - (void)isInQuietTime:(CDVInvokedUrlCommand *)command { completionHandler(CDVCommandStatus_OK, [NSNumber numberWithBool:inQuietTime]); }]; } - +*/ - (void)getLaunchNotification:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getLaunchNotification called with command arguments: %@", command.arguments); @@ -386,10 +357,10 @@ - (void)getChannelID:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getChannelID called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - completionHandler(CDVCommandStatus_OK, [UAirship channel].identifier ?: @""); + completionHandler(CDVCommandStatus_OK, [AirshipCordova.shared channelGetChannelIdOrEmpty] ?: @""); }]; } - +/* - (void)getQuietTime:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getQuietTime called with command arguments: %@", command.arguments); @@ -429,12 +400,12 @@ - (void)getQuietTime:(CDVInvokedUrlCommand *)command { @"endMinute": @(0) }); }]; } - +*/ - (void)getTags:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getTags called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - completionHandler(CDVCommandStatus_OK, [UAirship channel].tags ?: [NSArray array]); + completionHandler(CDVCommandStatus_OK, [AirshipCordova shared channelGetTags] ?: [NSArray array]); }]; } @@ -442,7 +413,7 @@ - (void)getBadgeNumber:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getBadgeNumber called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - completionHandler(CDVCommandStatus_OK, @([UIApplication sharedApplication].applicationIconBadgeNumber)); + completionHandler(CDVCommandStatus_OK, [AirshipCordova.shared pushGetBadgeNumber)]; }]; } @@ -450,7 +421,7 @@ - (void)getNamedUser:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getNamedUser called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - completionHandler(CDVCommandStatus_OK, UAirship.contact.namedUserID ?: @""); + completionHandler(CDVCommandStatus_OK, [AirshipCordova.shared contactGetNamedUserIdOrEmtpy] ?: @""); }]; } @@ -459,12 +430,13 @@ - (void)setTags:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSMutableArray *tags = [NSMutableArray arrayWithArray:[args objectAtIndex:0]]; - [UAirship channel].tags = tags; - [[UAirship channel] updateRegistration]; + + [AirshipCordova channelAddTags:tags]; completionHandler(CDVCommandStatus_OK, nil); }]; } +/* - (void)setQuietTimeEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setQuietTimeEnabled called with command arguments: %@", command.arguments); @@ -493,14 +465,14 @@ - (void)setQuietTime:(CDVInvokedUrlCommand *)command { completionHandler(CDVCommandStatus_OK, nil); }]; } - +*/ - (void)setAutobadgeEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setAutobadgeEnabled called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSNumber *number = [args objectAtIndex:0]; BOOL enabled = [number boolValue]; - [UAirship push].autobadgeEnabled = enabled; + [AirshipCordova.shared pushSetAutobadgeEnabled:enabled]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -512,7 +484,7 @@ - (void)setBadgeNumber:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { id number = [args objectAtIndex:0]; NSInteger badgeNumber = [number intValue]; - [[UAirship push] setBadgeNumber:badgeNumber]; + [AirshipCordova.shared pushSetBadgeNumber:badgeNumber]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -529,9 +501,9 @@ - (void)setNamedUser:(CDVInvokedUrlCommand *)command { } if (namedUserID.length) { - [UAirship.contact identify:namedUserID]; + [AirshipCordova.shared contactIdentify:namedUserID]; } else { - [UAirship.contact reset]; + [AirshipCordova.shared contactReset]; } completionHandler(CDVCommandStatus_OK, nil); }]; @@ -542,9 +514,7 @@ - (void)editNamedUserTagGroups:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [UAirship.contact editTagGroups:^(UATagGroupsEditor * editor) { - [self applyTagGroupEdits:[args objectAtIndex:0] editor:editor]; - }]; + [AirshipCordova.shared contactEditTagGroups:[args objectAtIndex:0]]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -555,67 +525,17 @@ - (void)editChannelTagGroups:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [UAirship.channel editTagGroups:^(UATagGroupsEditor * editor) { - [self applyTagGroupEdits:[args objectAtIndex:0] editor:editor]; - }]; + [AirshipCordova.shared channelEditTagGroups:[args objectAtIndex:0]]; completionHandler(CDVCommandStatus_OK, nil); }]; } -- (void)applyTagGroupEdits:(NSDictionary *)edits editor:(UATagGroupsEditor *)editor { - for (NSDictionary *edit in edits) { - NSString *group = edit[@"group"]; - if ([edit[@"operation"] isEqualToString:@"add"]) { - [editor addTags:edit[@"tags"] group:group]; - } else if ([edit[@"operation"] isEqualToString:@"remove"]) { - [editor removeTags:edit[@"tags"] group:group]; - } - } -} - -- (void)applyAttributeEdits:(NSDictionary *)edits editor:(UAAttributesEditor *)editor { - for (NSDictionary *edit in edits) { - NSString *action = edit[@"action"]; - NSString *name = edit[@"key"]; - - if ([action isEqualToString:@"set"]) { - id value = edit[@"value"]; - NSString *valueType = edit[@"type"]; - if ([valueType isEqualToString:@"string"]) { - [editor setString:value attribute:name]; - } else if ([valueType isEqualToString:@"number"]) { - [editor setNumber:value attribute:name]; - } else if ([valueType isEqualToString:@"date"]) { - // JavaScript's date type doesn't pass through the JS to native bridge. Dates are instead serialized as milliseconds since epoch. - NSDate *date = [NSDate dateWithTimeIntervalSince1970:[(NSNumber *)value doubleValue] / 1000.0]; - [editor setDate:date attribute:name]; - - } else { - UA_LWARN(@"Unknown attribute type: %@", valueType); - } - } else if ([action isEqualToString:@"remove"]) { - [editor removeAttribute:name]; - } - } -} - - (void)editChannelSubscriptionLists:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"editChannelSubscriptionLists called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [UAirship.channel editSubscriptionLists:^(UASubscriptionListEditor *editor) { - for (NSDictionary *edit in [args objectAtIndex:0]) { - NSString *listID = edit[@"listId"]; - NSString *operation = edit[@"operation"]; - - if ([operation isEqualToString:@"subscribe"]) { - [editor subscribe:listID]; - } else if ([operation isEqualToString:@"unsubscribe"]) { - [editor unsubscribe:listID]; - } - } - }]; + [AirshipCordova.shared channelEditSubscriptionLists: [args objectAtIndex:0]]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -624,61 +544,19 @@ - (void)editChannelSubscriptionLists:(CDVInvokedUrlCommand *)command { - (void)editContactSubscriptionLists:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"editContactSubscriptionLists called with command arguments: %@", command.arguments); - NSArray *allChannelScope = @[@"sms", @"email", @"app", @"web"]; - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [UAirship.contact editSubscriptionLists:^(UAScopedSubscriptionListEditor *editor) { - for (NSDictionary *edit in [args objectAtIndex:0]) { - NSString *listID = edit[@"listId"]; - NSString *scope = edit[@"scope"]; - NSString *operation = edit[@"operation"]; - - if ((listID != nil) & [allChannelScope containsObject:scope]) { - UAChannelScope channelScope = [self getScope:scope]; - if ([operation isEqualToString:@"subscribe"]) { - [editor subscribe:listID scope:channelScope]; - } else if ([operation isEqualToString:@"unsubscribe"]) { - [editor unsubscribe:listID scope:channelScope]; - } - } - } - }]; + [AirshipCordova.shared contactEditSubscriptionLists: [args objectAtIndex:0]]; completionHandler(CDVCommandStatus_OK, nil); }]; } -- (UAChannelScope)getScope:(NSString* )scope { - if ([scope isEqualToString:@"sms"]) { - return UAChannelScopeSms; - } else if ([scope isEqualToString:@"email"]) { - return UAChannelScopeEmail; - } else if ([scope isEqualToString:@"app"]) { - return UAChannelScopeApp; - } else { - return UAChannelScopeWeb; - } -} - -- (NSString *)getScopeString:(UAChannelScope )scope { - switch (scope) { - case UAChannelScopeSms: - return @"sms"; - case UAChannelScopeEmail: - return @"email"; - case UAChannelScopeApp: - return @"app"; - case UAChannelScopeWeb: - return @"web"; - } -} - - (void)getChannelSubscriptionLists:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getChannelSubscriptionLists called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAChannel shared] fetchSubscriptionListsWithCompletionHandler:^(NSArray * _Nullable channelSubscriptionLists, NSError * _Nullable error) { + [AirshipCordova.shared channelGetSubscriptionListsWithCompletionHandler:^(NSArray * _Nullable channelSubscriptionLists, NSError * _Nullable error) { if (error) { completionHandler(CDVCommandStatus_ERROR, error); } @@ -696,7 +574,7 @@ - (void)getContactSubscriptionLists:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAContact shared] fetchSubscriptionListsWithCompletionHandler:^(NSDictionary * _Nullable contactSubscriptionLists, NSError * _Nullable error) { + [AirshipCordova.shared contactGetSubscriptionListsWithCompletionHandler:^(NSDictionary * _Nullable contactSubscriptionLists, NSError * _Nullable error) { if (error) { completionHandler(CDVCommandStatus_ERROR, error); } @@ -720,18 +598,6 @@ - (void)getContactSubscriptionLists:(CDVInvokedUrlCommand *)command { }]; } - -- (void)resetBadge:(CDVInvokedUrlCommand *)command { - UA_LTRACE(@"resetBadge called with command arguments: %@", command.arguments); - - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAirship push] resetBadge]; - [[UAirship push] updateRegistration]; - - completionHandler(CDVCommandStatus_OK, nil); - }]; -} - - (void)trackScreen:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"trackScreen called with command arguments: %@", command.arguments); @@ -740,7 +606,7 @@ - (void)trackScreen:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"trackScreen set to:%@", screen); - [[UAirship analytics] trackScreen:screen]; + [AirshipCordova.shared analyticsTrackScreen:screen]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -752,35 +618,33 @@ - (void)runAction:(CDVInvokedUrlCommand *)command { NSString *actionName = [args firstObject]; id actionValue = args.count >= 2 ? [args objectAtIndex:1] : nil; - [UAActionRunner runActionWithName:actionName - value:actionValue - situation:UASituationManualInvocation - completionHandler:^(UAActionResult *actionResult) { - - if (actionResult.status == UAActionStatusCompleted) { + [AirshipCordova.shared actionsRunWithActionName:name + actionValue:value + completionHandler:^(id result , NSError *error) { - /* - * We are wrapping the value in an object to be consistent - * with the Android implementation. - */ + /* + if (result.status == UAActionStatusCompleted) { NSMutableDictionary *result = [NSMutableDictionary dictionary]; - [result setValue:actionResult.value forKey:@"value"]; + [result setValue:result.value forKey:@"value"]; completionHandler(CDVCommandStatus_OK, result); } else { - NSString *error = [self errorMessageForAction:actionName result:actionResult]; + NSString *error = [self errorMessageForAction:actionName result:result]; completionHandler(CDVCommandStatus_ERROR, error); } + */ + completionHandler(CDVCommandStatus_OK, nil); }]; }]; + } - (void)isAppNotificationsEnabled:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"isAppNotificationsEnabled called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - BOOL optedIn = [UAirship push].authorizedNotificationSettings != 0; + BOOL optedIn = [AirshipCordova.shared pushGetAuthorizedNotificationSettings] != 0; completionHandler(CDVCommandStatus_OK, [NSNumber numberWithBool:optedIn]); }]; } @@ -792,7 +656,9 @@ - (void)isAppNotificationsEnabled:(CDVInvokedUrlCommand *)command { * @param actionResult The action result. * @return An error message, or nil if no error was found. */ +/* - (NSString *)errorMessageForAction:(NSString *)actionName result:(UAActionResult *)actionResult { + switch (actionResult.status) { case UAActionStatusActionNotFound: return [NSString stringWithFormat:@"Action %@ not found.", actionName]; @@ -808,22 +674,13 @@ - (NSString *)errorMessageForAction:(NSString *)actionName result:(UAActionResul return [NSString stringWithFormat:@"Action %@ failed with unspecified error", actionName]; } - - -- (void)displayMessageCenter:(CDVInvokedUrlCommand *)command { - UA_LTRACE(@"displayMessageCenter called with command arguments: %@", command.arguments); - - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAMessageCenter shared] display]; - completionHandler(CDVCommandStatus_OK, nil); - }]; -} +*/ - (void)dismissMessageCenter:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"dismissMessageCenter called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAMessageCenter shared] dismiss]; + [AirshipCordova.shared messageCenterDismiss]; completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -833,44 +690,21 @@ - (void)getInboxMessages:(CDVInvokedUrlCommand *)command { UA_LDEBUG(@"Getting messages"); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - NSMutableArray *messages = [NSMutableArray array]; - - for (UAInboxMessage *message in [UAMessageCenter shared].messageList.messages) { - - NSDictionary *icons = [message.rawMessageObject objectForKey:@"icons"]; - NSString *iconUrl = [icons objectForKey:@"list_icon"]; - NSNumber *sentDate = @([message.messageSent timeIntervalSince1970] * 1000); - - NSMutableDictionary *messageInfo = [NSMutableDictionary dictionary]; - [messageInfo setValue:message.title forKey:@"title"]; - [messageInfo setValue:message.messageID forKey:@"id"]; - [messageInfo setValue:sentDate forKey:@"sentDate"]; - [messageInfo setValue:iconUrl forKey:@"listIconUrl"]; - [messageInfo setValue:message.unread ? @NO : @YES forKey:@"isRead"]; - [messageInfo setValue:message.extra forKey:@"extras"]; - - [messages addObject:messageInfo]; + NSMutableArray *messages = [AirshipCordova.shared messageCenterGetMessagesWithCompletionHandler:^(NSArray *result, NSError *error) { + completionHandler(CDVCommandStatus_OK, result); } - - completionHandler(CDVCommandStatus_OK, messages); }]; + } - (void)markInboxMessageRead:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"markInboxMessageRead called with command arguments: %@", command.arguments); - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSString *messageID = [command.arguments firstObject]; - UAInboxMessage *message = [[UAMessageCenter shared].messageList messageForID:messageID]; - - if (!message) { - NSString *error = [NSString stringWithFormat:@"Message not found: %@", messageID]; - completionHandler(CDVCommandStatus_ERROR, error); - return; + [AirshipCordova.shared messageCenterMarkMessageReadWithMessageId:messageId + completionHandler:^(NSError * error) { + completionHandler(CDVCommandStatus_OK, nil); } - - [[UAMessageCenter shared].messageList markMessagesRead:@[message] completionHandler:nil]; - completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -879,58 +713,39 @@ - (void)deleteInboxMessage:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSString *messageID = [command.arguments firstObject]; - UAInboxMessage *message = [[UAMessageCenter shared].messageList messageForID:messageID]; - - if (!message) { - NSString *error = [NSString stringWithFormat:@"Message not found: %@", messageID]; - completionHandler(CDVCommandStatus_ERROR, error); - return; + [AirshipCordova.shared messageCenterDeleteMessageWithMessageId:messageId + completionHandler:^(NSError * error) { + completionHandler(CDVCommandStatus_OK, nil); } - - [[UAMessageCenter shared].messageList markMessagesDeleted:@[message] completionHandler:nil]; - completionHandler(CDVCommandStatus_OK, nil); }]; + } - (void)displayInboxMessage:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"displayInboxMessage called with command arguments: %@", command.arguments); - - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [self.messageViewController dismissViewControllerAnimated:YES completion:nil]; - - UAMessageViewController *mvc = [[UAMessageViewController alloc] init]; - mvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; - mvc.modalPresentationStyle = UIModalPresentationFullScreen; - [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:mvc animated:YES completion:nil]; - - // Load the message - [mvc loadMessageForID:[command.arguments firstObject]]; - - // Store a weak reference to the MessageViewController so we can dismiss it later - self.messageViewController = mvc; - - completionHandler(CDVCommandStatus_OK, nil); - }]; -} - -- (void)dismissInboxMessage:(CDVInvokedUrlCommand *)command { - UA_LTRACE(@"dismissInboxMessage called with command arguments: %@", command.arguments); - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [self.messageViewController dismissViewControllerAnimated:YES completion:nil]; - self.messageViewController = nil; - completionHandler(CDVCommandStatus_OK, nil); + + + [AirshipCordova.shared messageCenterDisplayWithMessageId:[command.arguments firstObject] + error:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; } - (void)refreshInbox:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"refreshInbox called with command arguments: %@", command.arguments); - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAMessageCenter shared].messageList retrieveMessageListWithSuccessBlock:^{ - completionHandler(CDVCommandStatus_OK, nil); - } withFailureBlock:^{ - completionHandler(CDVCommandStatus_ERROR, @"Inbox failed to refresh"); + [AirshipCordova.shared messageCenterRefreshWithCompletionHandler:^(NSError *error) { + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; }]; } @@ -939,20 +754,9 @@ - (void)getActiveNotifications:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getActiveNotifications called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - if (@available(iOS 10.0, *)) { - [[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray * _Nonnull notifications) { - - NSMutableArray *result = [NSMutableArray array]; - for(UNNotification *unnotification in notifications) { - UNNotificationContent *content = unnotification.request.content; - [result addObject:[UACordovaPushEvent pushEventDataFromNotificationContent:content.userInfo]]; - } - - completionHandler(CDVCommandStatus_OK, result); - }]; - } else { - completionHandler(CDVCommandStatus_ERROR, @"Only available on iOS 10+"); - } + [AirshipCordova.shared pushGetActiveNotificationsWithCompletionHandler:^(NSArray *> *result) { + completionHandler(CDVCommandStatus_OK, result); + }]; }]; } @@ -960,15 +764,11 @@ - (void)clearNotification:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"clearNotification called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - if (@available(iOS 10.0, *)) { - NSString *identifier = command.arguments.firstObject; - - if (identifier) { - [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[identifier]]; - } + + NSString *identifier = command.arguments.firstObject; + [AirshipCordova.shared pushClearNotification:identifier]; - completionHandler(CDVCommandStatus_OK, nil); - } + completionHandler(CDVCommandStatus_OK, nil); }]; } @@ -976,9 +776,7 @@ - (void)clearNotifications:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"clearNotifications called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - if (@available(iOS 10.0, *)) { - [[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications]; - } + [AirshipCordova.shared pushClearNotifications]; completionHandler(CDVCommandStatus_OK, nil); }]; @@ -988,10 +786,15 @@ - (void)editChannelAttributes:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"editChannelAttributes called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - - [UAirship.channel editAttributes:^(UAAttributesEditor *editor) { - [self applyAttributeEdits:[args objectAtIndex:0] editor:editor]; - }]; + NSError *error; + [AirshipCordova.shared channelEditAttributesWithJson:[args objectAtIndex:0] + error:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; } @@ -999,9 +802,14 @@ - (void)editNamedUserAttributes:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"editNamedUserAttributes called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [UAirship.contact editAttributes:^(UAAttributesEditor *editor) { - [self applyAttributeEdits:[args objectAtIndex:0] editor:editor]; - }]; + NSError *error; + [AirshipCordova.shared contactEditAttributesWithJson:[args objectAtIndex:0] + error:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; } @@ -1032,8 +840,14 @@ - (void)enableFeature:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSArray *features = [args firstObject]; if ([self isValidFeature:features]) { - [[UAirship shared].privacyManager enableFeatures:[self stringToFeature:features]]; - completionHandler(CDVCommandStatus_OK, nil); + NSError *error; + [AirshipCordova.shared privacyManagerEnableFeatureWithFeatures:features error:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } } else { completionHandler(CDVCommandStatus_ERROR, @"Invalid feature, cancelling the action."); } @@ -1046,8 +860,14 @@ - (void)disableFeature:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSArray *features = [args firstObject]; if ([self isValidFeature:features]) { - [[UAirship shared].privacyManager disableFeatures:[self stringToFeature:features]]; - completionHandler(CDVCommandStatus_OK, nil); + NSError *error; + [AirshipCordova.shared privacyManagerEnableFeatureWithFeatures:[self stringToFeature:features] error:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } } else { completionHandler(CDVCommandStatus_ERROR, @"Invalid feature, cancelling the action."); } @@ -1060,8 +880,15 @@ - (void)setEnabledFeatures:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSArray *features = [args firstObject]; if ([self isValidFeature:features]) { - [UAirship shared].privacyManager.enabledFeatures = [self stringToFeature:features]; - completionHandler(CDVCommandStatus_OK, nil); + NSError *error; + [AirshipCordova.shared privacyManagerSetEnabledFeaturesWithFeatures:[self stringToFeature:features] error:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } + } else { completionHandler(CDVCommandStatus_ERROR, @"Invalid feature, cancelling the action."); } @@ -1072,7 +899,14 @@ - (void)getEnabledFeatures:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getEnabledFeatures called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - completionHandler(CDVCommandStatus_OK, [self featureToString:[UAirship shared].privacyManager.enabledFeatures]); + NSError *error; + id result = [AirshipCordova.shared privacyManagerGetEnabledFeaturesAndReturnError:&error]; + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, [self featureToString:result]); + } }]; } @@ -1082,7 +916,14 @@ - (void)isFeatureEnabled:(CDVInvokedUrlCommand *)command { [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSArray *features = [args firstObject]; if ([self isValidFeature:features]) { - completionHandler(CDVCommandStatus_OK, @([[UAirship shared].privacyManager isEnabled:[self stringToFeature:features]])); + NSError *error; + id result = [AirshipCordova.shared privacyManagerIsFeatureEnabledWithFeatures:[self stringToFeature:features] + error:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, result); + } } else { completionHandler(CDVCommandStatus_ERROR, @"Invalid feature, cancelling the action."); } @@ -1093,20 +934,31 @@ - (void)openPreferenceCenter:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"openPreferenceCenter called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - NSString *preferenceCenterID = [args firstObject]; - [[UAPreferenceCenter shared] openPreferenceCenter:preferenceCenterID]; - completionHandler(CDVCommandStatus_OK, nil); + NSString *preferenceCenterId = [args firstObject]; + NSError *error; + [AirshipCordova.shared preferenceCenterDisplayWithPreferenceCenterId:preferenceCenterId + error:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; } - (void)getPreferenceCenterConfig:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getPreferenceCenterConfig called with command arguments: %@", command.arguments); - [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - NSString *preferenceCenterID = [args firstObject]; - [[UAPreferenceCenter shared] jsonConfigForPreferenceCenterID:preferenceCenterID completionHandler:^(NSDictionary *config) { - completionHandler(CDVCommandStatus_OK, config); - }]; - }]; + NSString *preferenceCenterId = [args firstObject]; + [AirshipCordova.shared preferenceCenterGetConfigWithPreferenceCenterId:preferenceCenterId + completionHandler:^(id result, NSError *error) { + + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, result); + } + + } } - (void)setUseCustomPreferenceCenterUi:(CDVInvokedUrlCommand *)command { @@ -1122,8 +974,14 @@ - (void)setUseCustomPreferenceCenterUi:(CDVInvokedUrlCommand *)command { - (void)getCurrentLocale:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"getCurrentLocale called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - NSLocale *airshipLocale = [[UAirship shared].localeManager currentLocale]; - completionHandler(CDVCommandStatus_OK, airshipLocale.localeIdentifier); + NSError *error; + NSLocale *airshipLocale = [AirshipCordova.shared localeGetLocaleAndReturnError:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, completionHandler(CDVCommandStatus_OK, airshipLocale.localeIdentifier); + } + }]; } @@ -1131,16 +989,28 @@ - (void)setCurrentLocale:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"setCurrentLocale called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { NSString *localeIdentifier = [args firstObject]; - [UAirship.shared.localeManager setCurrentLocale:[NSLocale localeWithLocaleIdentifier:localeIdentifier]]; - completionHandler(CDVCommandStatus_OK, nil); + NSError *error; + [AirshipCordova.shared localeSetLocaleOverrideWithLocaleIdentifier:localeIdentifier + error:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, completionHandler(CDVCommandStatus_OK, nil); + } + }]; } - (void)clearLocale:(CDVInvokedUrlCommand *)command { UA_LTRACE(@"clearLocale called with command arguments: %@", command.arguments); [self performCallbackWithCommand:command withBlock:^(NSArray *args, UACordovaCompletionHandler completionHandler) { - [[UAirship shared].localeManager clearLocale]; - completionHandler(CDVCommandStatus_OK, nil); + NSError *error; + [AirshipCordova.shared localeClearLocaleOverrideAndReturnError:&error]; + if (error) { + completionHandler(CDVCommandStatus_ERROR, error); + } else { + completionHandler(CDVCommandStatus_OK, nil); + } }]; } @@ -1201,11 +1071,9 @@ - (NSDictionary *)authorizedFeatures { [authorizedFeatures setValue:@(UAFeaturesInAppAutomation) forKey:@"FEATURE_IN_APP_AUTOMATION"]; [authorizedFeatures setValue:@(UAFeaturesMessageCenter) forKey:@"FEATURE_MESSAGE_CENTER"]; [authorizedFeatures setValue:@(UAFeaturesPush) forKey:@"FEATURE_PUSH"]; - [authorizedFeatures setValue:@(UAFeaturesChat) forKey:@"FEATURE_CHAT"]; [authorizedFeatures setValue:@(UAFeaturesAnalytics) forKey:@"FEATURE_ANALYTICS"]; [authorizedFeatures setValue:@(UAFeaturesTagsAndAttributes) forKey:@"FEATURE_TAGS_AND_ATTRIBUTES"]; [authorizedFeatures setValue:@(UAFeaturesContacts) forKey:@"FEATURE_CONTACTS"]; - [authorizedFeatures setValue:@(UAFeaturesLocation) forKey:@"FEATURE_LOCATION"]; [authorizedFeatures setValue:@(UAFeaturesAll) forKey:@"FEATURE_ALL"]; return authorizedFeatures; } diff --git a/urbanairship-cordova/www/AirshipActions.mjs b/urbanairship-cordova/www/AirshipActions.mjs new file mode 100644 index 00000000..9d61b2cc --- /dev/null +++ b/urbanairship-cordova/www/AirshipActions.mjs @@ -0,0 +1,59 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipActions { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + + /** + * @module AirshipActions + */ + module.exports = { + + /** + * Runs an Urban Airship action. + * + * @param {String} actionName action as a string. + * @param {*} actionValue + * @param {function(result)} [success] The function to call on success. + * @param {object} success.result The result's value. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + runAction: function(actionName, actionValue, success, failure) { + argscheck.checkArgs('s*FF', 'UAirship.runAction', arguments) + _runAction(actionName, actionValue, success, failure) + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipAnalytics.mjs b/urbanairship-cordova/www/AirshipAnalytics.mjs new file mode 100644 index 00000000..839c8f75 --- /dev/null +++ b/urbanairship-cordova/www/AirshipAnalytics.mjs @@ -0,0 +1,97 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipAnalytics { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + + /** + * @module AirshipAnalytics + */ + module.exports = { + + /** + * Sets an associated identifier for the Connect data stream. + * + * @param {string} Custom key for identifier. + * @param {string} The identifier value. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setAssociatedIdentifier: function(key, identifier, success, failure) { + argscheck.checkArgs('ssFF', 'UAirship.setAssociatedIdentifier', arguments) + callNative(success, failure, "setAssociatedIdentifier", [key, identifier]) + }, + + /** + /** + * Adds a custom event. + * + * @param {object} event The custom event object. + * @param {string} event.name The event's name. + * @param {number} [event.value] The event's value. + * @param {string} [event.transactionId] The event's transaction ID. + * @param {object} [event.properties] The event's properties. Only numbers, booleans, strings, and array of strings are supported. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + addCustomEvent: function(event, success, failure) { + argscheck.checkArgs('oFF', 'UAirship.addCustomEvent', arguments) + + var actionArg = { + event_name: event.name, + event_value: event.value, + transaction_id: event.transactionId, + properties: event.properties + } + + _runAction("add_custom_event_action", actionArg, success, failure) + }, + + /** + * Initiates screen tracking for a specific app screen, must be called once per tracked screen. + * + * @param {string} screen The screen's string identifier. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + trackScreen: function(screen, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.trackScreen', arguments) + callNative(success, failure, "trackScreen", [screen]) + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipChannel.mjs b/urbanairship-cordova/www/AirshipChannel.mjs new file mode 100644 index 00000000..49a20002 --- /dev/null +++ b/urbanairship-cordova/www/AirshipChannel.mjs @@ -0,0 +1,110 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipChannel { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + /** + * @module AirshipChannel + */ + module.exports = { + + /** + * Returns the channel ID. + * + * @param {function(ID)} success The function to call on success. + * @param {string} success.ID The channel ID string + * @param {failureCallback} [failure] The function to call on failure. + * @param {string} failure.message The error message. + */ + getChannelID: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getChannelID', arguments) + callNative(success, failure, "getChannelID") + }, + + /** + * Returns the tags as an array. + * + * @param {function(tags)} success The function to call on success. + * @param {array} success.tags The tags as an array. + * @param {failureCallback} [failure] The function to call on failure. + * @param {string} failure.message The error message. + */ + getTags: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getTags', arguments); + callNative(success, failure, "getTags") + }, + + /** + * Sets the tags. + * + * @param {Array} tags an array of strings. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setTags: function(tags, success, failure) { + argscheck.checkArgs('aFF', 'UAirship.setTags', arguments); + callNative(success, failure, "setTags", [tags]) + }, + + + /** + * Creates an editor to modify the channel tag groups. + * + * @return {TagGroupEditor} A tag group editor instance. + */ + editChannelTagGroups: function() { + return new TagGroupEditor('editChannelTagGroups') + }, + + /** + * Creates an editor to modify the channel attributes. + * + * @return {AttributesEditor} An attributes editor instance. + */ + editChannelAttributes: function() { + return new AttributesEditor('editChannelAttributes') + }, + + /** + * Creates an editor to modify the channel subscription lists. + * + * @return {ChannelSubscriptionListEditor} A subscription list editor instance. + */ + editChannelSubscriptionLists: function() { + return new ChannelSubscriptionListEditor('editChannelSubscriptionLists') + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipContact.mjs b/urbanairship-cordova/www/AirshipContact.mjs new file mode 100644 index 00000000..e6df1143 --- /dev/null +++ b/urbanairship-cordova/www/AirshipContact.mjs @@ -0,0 +1,96 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipContact { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + /** + * @module AirshipContact + */ + module.exports = { + + /** + * Returns the named user ID. + * + * @param {function(namedUser)} success The function to call on success. + * @param {string} success.namedUser The named user ID as a string. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getNamedUser: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getNamedUser', arguments) + callNative(success, failure, "getNamedUser") + }, + + /** + * Sets the named user ID. + * + * @param {String} namedUser identifier string. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setNamedUser: function(namedUser, success, failure) { + argscheck.checkArgs('SFF', 'UAirship.setNamedUser', arguments) + callNative(success, failure, "setNamedUser", [namedUser]) + }, + + /** + * Creates an editor to modify the named user tag groups. + * + * @return {TagGroupEditor} A tag group editor instance. + */ + editNamedUserTagGroups: function() { + return new TagGroupEditor('editNamedUserTagGroups') + }, + + /** + * Creates an editor to modify the contact subscription lists. + * + * @return {ContacttSubscriptionListEditor} A subscription list editor instance. + */ + editContactSubscriptionLists: function() { + return new ContactSubscriptionListEditor('editContactSubscriptionLists') + }, + + /** + * Creates an editor to modify the named user attributes. + * + * @return {AttributesEditor} An attributes editor instance. + */ + editNamedUserAttributes: function() { + return new AttributesEditor('editNamedUserAttributes') + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipLocale.mjs b/urbanairship-cordova/www/AirshipLocale.mjs new file mode 100644 index 00000000..b2a90b40 --- /dev/null +++ b/urbanairship-cordova/www/AirshipLocale.mjs @@ -0,0 +1,77 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipLocale { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + + /** + * @module AirshipLocale + */ + module.exports = { + + /** + * Overriding the locale. + * + * @param {string} localeIdentifier The locale identifier. + */ + setCurrentLocale: function(localeIdentifier, success, failure) { + argscheck.checkArgs("sFF", "UAirship.setCurrentLocale", arguments) + callNative(success, failure, "setCurrentLocale", [localeIdentifier]) + }, + + /** + * Getting the locale currently used by Airship. + * + * @param {function} [success] Success callback. + * @param {string} failure.message The error message. + */ + getCurrentLocale: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getCurrentLocale', arguments) + callNative(success, failure, "getCurrentLocale") + }, + + /** + * Resets the current locale. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + clearLocale: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.clearLocale', arguments) + callNative(success, failure, "clearLocale") + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipMessageCenter.mjs b/urbanairship-cordova/www/AirshipMessageCenter.mjs new file mode 100644 index 00000000..49311f97 --- /dev/null +++ b/urbanairship-cordova/www/AirshipMessageCenter.mjs @@ -0,0 +1,153 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipMessageCenter { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + /** + * @module AirshipMessageCenter + */ + module.exports = { + + + /** + * Displays the message center. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + displayMessageCenter: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.displayMessageCenter', arguments) + callNative(success, failure, "displayMessageCenter") + }, + + /** + * Dismiss the message center. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + dismissMessageCenter: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.dismissMessageCenter', arguments) + callNative(success, failure, "dismissMessageCenter") + }, + + /** + * Dismiss the inbox message. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + dismissInboxMessage: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.dismissInboxMessage', arguments) + callNative(success, failure, "dismissInboxMessage") + }, + + /** + * Gets the array of inbox messages. Each message will have the following properties: + * "id": string - The messages ID. Needed to display, mark as read, or delete the message. + * "title": string - The message title. + * "sentDate": number - The message sent date in milliseconds. + * "listIconUrl": string, optional - The icon url for the message. + * "isRead": boolean - The unread/read status of the message. + * "extras": object - String to String map of any message extras. + * + * @param {function(messages)} success The function to call on success. + * @param {array} success.messages The array of inbox messages. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getInboxMessages: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getInboxMessages', arguments) + callNative(success, failure, "getInboxMessages") + }, + + /** + * Marks an inbox message read. + * + * @param {String} messageId The ID of the message to mark as read. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + markInboxMessageRead: function(messageId, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.markInboxMessageRead', arguments) + callNative(success, failure, 'markInboxMessageRead', [messageId]) + }, + + /** + * Deletes an inbox message. + * + * @param {String} messageId The ID of the message to delete. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + deleteInboxMessage: function(messageId, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.deleteInboxMessage', arguments) + callNative(success, failure, 'deleteInboxMessage', [messageId]) + }, + + /** + * Displays the inbox message using a full screen view. + * + * @param {String} messageId The ID of the message to display. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + displayInboxMessage: function(messageId, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.displayInboxMessage', arguments) + callNative(success, failure, 'displayInboxMessage', [messageId]) + }, + + /** + * Forces the inbox to refresh. This is normally not needed as the inbox + * will automatically refresh on foreground or when a push arrives thats + * associated with a message, but it can be useful when providing a refresh + * button for the message listing. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + refreshInbox: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.refreshInbox', arguments) + callNative(success, failure, 'refreshInbox') + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipPreferenceCenter.mjs b/urbanairship-cordova/www/AirshipPreferenceCenter.mjs new file mode 100644 index 00000000..a706addf --- /dev/null +++ b/urbanairship-cordova/www/AirshipPreferenceCenter.mjs @@ -0,0 +1,107 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipPreferenceCenter { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + + /** + * @module AirshipPreferenceCenter + */ + module.exports = { + + /** + * Opens the Preference Center with the given preferenceCenterId. + * + * @param {string} preferenceCenterId The preference center ID. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + openPreferenceCenter: function(preferenceCenterId, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.openPreferenceCenter', arguments) + callNative(success, failure, "openPreferenceCenter", [preferenceCenterId]) + }, + + /** + * Returns the configuration of the Preference Center with the given ID trough a callback method. + * + * @param {string} preferenceCenterId The preference center ID. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getPreferenceCenterConfig: function(preferenceCenterId, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.getPreferenceCenterConfig', arguments) + callNative(success, failure, "getPreferenceCenterConfig", [preferenceCenterId]) + }, + + /** + * Returns the current set of subscription lists for the current channel, + * optionally applying pending subscription list changes that will be applied during the next channel update. + * An empty set indicates that this contact is not subscribed to any lists. + * + * @param {function} [success] Success callback. + * @param {string} failure.message The error message. + */ + getChannelSubscriptionLists: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getChannelSubscriptionLists', arguments) + callNative(success, failure, "getChannelSubscriptionLists") + }, + + /** + * Returns the current set of subscription lists for the current contact, + * optionally applying pending subscription list changes that will be applied during the next contact update. + * An empty set indicates that this contact is not subscribed to any lists. + * + * @param {function} [success] Success callback. + * @param {string} failure.message The error message. + */ + getContactSubscriptionLists: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getContactSubscriptionLists', arguments) + callNative(success, failure, "getContactSubscriptionLists") + }, + + /** + * Sets the use custom preference center. + * + * @param {string} preferenceCenterId The preference center ID. + * @param {boolean} useCustomUi The preference center use custom UI. + */ + setUseCustomPreferenceCenterUi: function(preferenceCenterId, useCustomUi, success, failure) { + argscheck.checkArgs("s*FF", "UAirship.setUseCustomPreferenceCenterUi", arguments) + callNative(success, failure, "setUseCustomPreferenceCenterUi", [preferenceCenterId, useCustomUi]) + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipPrivacyManager.mjs b/urbanairship-cordova/www/AirshipPrivacyManager.mjs new file mode 100644 index 00000000..dd808819 --- /dev/null +++ b/urbanairship-cordova/www/AirshipPrivacyManager.mjs @@ -0,0 +1,160 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipPrivacyManager { + + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + /** + * Constant for Feature NONE. + */ + const FEATURE_NONE = "FEATURE_NONE" + /** + * Constant for InApp Automation Feature. + */ + const FEATURE_IN_APP_AUTOMATION = "FEATURE_IN_APP_AUTOMATION" + /** + * Constant for Message Center Feature. + */ + const FEATURE_MESSAGE_CENTER = "FEATURE_MESSAGE_CENTER" + /** + * Constant for Push Feature. + */ + const FEATURE_PUSH = "FEATURE_PUSH" + /** + * Constant for Chat Feature. + */ + const FEATURE_CHAT = "FEATURE_CHAT" + /** + * Constant for Analytics Feature. + */ + const FEATURE_ANALYTICS = "FEATURE_ANALYTICS" + /** + * Constant for Tags and Attributes Feature. + */ + const FEATURE_TAGS_AND_ATTRIBUTES = "FEATURE_TAGS_AND_ATTRIBUTES" + /** + * Constant for Contacts Feature. + */ + const FEATURE_CONTACTS = "FEATURE_CONTACTS" + /** + * Constant for Location Feature. + */ + const FEATURE_LOCATION = "FEATURE_LOCATION" + /** + * Constant for all Feature. + */ + const FEATURE_ALL = "FEATURE_ALL" + + /** + * @module AirshipPrivacyManager + */ + module.exports = { + + FEATURE_NONE: FEATURE_NONE, + FEATURE_IN_APP_AUTOMATION: FEATURE_IN_APP_AUTOMATION, + FEATURE_MESSAGE_CENTER: FEATURE_MESSAGE_CENTER, + FEATURE_PUSH: FEATURE_PUSH, + FEATURE_CHAT: FEATURE_CHAT, + FEATURE_ANALYTICS: FEATURE_ANALYTICS, + FEATURE_TAGS_AND_ATTRIBUTES: FEATURE_TAGS_AND_ATTRIBUTES, + FEATURE_CONTACTS: FEATURE_CONTACTS, + FEATURE_LOCATION: FEATURE_LOCATION, + FEATURE_ALL: FEATURE_ALL, + + /** + * Enables features, adding them to the set of currently enabled features. + * + * @param {array} features The features to enable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + enableFeature: function(features, success, failure) { + argscheck.checkArgs('aFF', 'UAirship.enableFeature', arguments) + callNative(success, failure, "enableFeature", [features]) + }, + + /** + * Disables features, removing them from the set of currently enabled features. + * + * @param {array} features The features to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + disableFeature: function(features, success, failure) { + argscheck.checkArgs('aFF', 'UAirship.disableFeature', arguments) + callNative(success, failure, "disableFeature", [features]) + }, + + /** + * Sets the current enabled features, replacing any currently enabled features with the given set. + * + * @param {array} features The features to set as enabled. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setEnabledFeatures: function(features, success, failure) { + argscheck.checkArgs('aFF', 'UAirship.setEnabledFeatures', arguments) + callNative(success, failure, "setEnabledFeatures", [features]) + }, + + /** + * Gets the current enabled features. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getEnabledFeatures: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.getEnabledFeatures', arguments) + callNative(success, failure, "getEnabledFeatures") + }, + + /** + * Checks if all of the given features are enabled. + * + * @param {array} features The features to check. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isFeatureEnabled: function(features, success, failure) { + argscheck.checkArgs('aFF', 'UAirship.isFeatureEnabled', arguments) + callNative(success, failure, "isFeatureEnabled", [features]) + } + + } + +} diff --git a/urbanairship-cordova/www/AirshipPush.mjs b/urbanairship-cordova/www/AirshipPush.mjs new file mode 100644 index 00000000..030ec2b5 --- /dev/null +++ b/urbanairship-cordova/www/AirshipPush.mjs @@ -0,0 +1,382 @@ +/* Copyright Urban Airship and Contributors */ + +export class AirshipPush { + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + /** + * @module AirshipPush + */ + module.exports = { + + /** + * Enables or disables user notifications. + * + * @param {boolean} enabled true to enable notifications, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setUserNotificationsEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setUserNotificationsEnabled', arguments) + callNative(success, failure, "setUserNotificationsEnabled", [!!enabled]) + }, + + /** + * Checks if user notifications are enabled or not. + * + * @param {function(enabled)} success Success callback. + * @param {boolean} success.enabled Flag indicating if user notifications is enabled or not. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isUserNotificationsEnabled: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.isUserNotificationsEnabled', arguments) + callNative(success, failure, "isUserNotificationsEnabled") + }, + + /** + * Enables user notifications. + * + * @param {function} success Success callback. + * @param {boolean} success.enabled Flag indicating if user notifications enablement was authorized or not. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + enableUserNotifications: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.enableUserNotifications', arguments) + callNative(success, failure, "enableUserNotifications") + }, + + /** + * Returns the last notification that launched the application. + * + * @param {Boolean} clear true to clear the notification. + * @param {function(push)} success The function to call on success. + * @param {object} success.push The push message object containing data associated with a push notification. + * @param {string} success.push.message The push alert message. + * @param {object} success.push.extras Any push extras. + * @param {number} [success.push.notification_id] The Android notification ID. + * @param {failureCallback} [failure] The function to call on failure. + * @param {string} failure.message The error message. + */ + getLaunchNotification: function(clear, success, failure) { + argscheck.checkArgs('*fF', 'UAirship.getLaunchNotification', arguments) + callNative(success, failure, "getLaunchNotification", [!!clear]) + }, + + /** + * Checks if quiet time is enabled or not. + * + * @param {function(enabled)} success Success callback. + * @param {boolean} success.enabled Flag indicating if quiet time is enabled or not. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isQuietTimeEnabled: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.isQuietTimeEnabled', arguments) + callNative(success, failure, "isQuietTimeEnabled") + }, + + /** + * Enables or disables quiet time. + * + * @param {Boolean} enabled true to enable quiet time, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setQuietTimeEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setQuietTimeEnabled', arguments) + callNative(success, failure, "setQuietTimeEnabled", [!!enabled]) + }, + + /** + * Checks if the device is currently in quiet time. + * + * @param {function(inQuietTime)} success Success callback. + * @param {boolean} success.inQuietTime Flag indicating if quiet time is currently in effect. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isInQuietTime: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.isInQuietTime', arguments) + callNative(success, failure, "isInQuietTime") + }, + + /** + * Returns the quiet time as an object with the following: + * "startHour": Number, + * "startMinute": Number, + * "endHour": Number, + * "endMinute": Number + * + * @param {function(quietTime)} success The function to call on success. + * @param {object} success.quietTime The quietTime object represents a timespan during + * which notifications should be silenced. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getQuietTime: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getQuietTime', arguments) + callNative(success, failure, "getQuietTime") + }, + + /** + * Sets the quiet time. + * + * @param {Number} startHour for quiet time. + * @param {Number} startMinute for quiet time. + * @param {Number} endHour for quiet time. + * @param {Number} endMinute for quiet time. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setQuietTime: function(startHour, startMinute, endHour, endMinute, success, failure) { + argscheck.checkArgs('nnnnFF', 'UAirship.setQuietTime', arguments) + callNative(success, failure, "setQuietTime", [startHour, startMinute, endHour, endMinute]) + }, + + /** + * Clears a notification by identifier. + * + * @param {string} identifier The notification identifier. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + */ + clearNotification: function(identifier, success, failure) { + argscheck.checkArgs('sFF', 'UAirship.clearNotification', arguments) + callNative(success, failure, "clearNotification", [identifier]) + }, + + /** + * Clears all notifications posted by the application. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + clearNotifications: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.clearNotifications', arguments) + callNative(success, failure, "clearNotifications") + }, + + /** + * Gets currently active notifications. + * + * Note: On Android this functionality is only supported on Android M or higher. + * + * @param {function(messages)} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + */ + getActiveNotifications: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getActiveNotifications', arguments) + callNative(success, failure, "getActiveNotifications") + }, + + // iOS only + + /** + * Enables or disables auto badge. Defaults to `NO`. + * + * @param {Boolean} enabled true to enable auto badge, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setAutobadgeEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setAutobadgeEnabled', arguments) + callNative(success, failure, "setAutobadgeEnabled", [!!enabled]) + }, + + /** + * Sets the badge number. + * + * @param {Number} number specified badge to set. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setBadgeNumber: function(number, success, failure) { + argscheck.checkArgs('nFF', 'UAirship.setBadgeNumber', arguments) + callNative(success, failure, "setBadgeNumber", [number]) + }, + + /** + * Returns the current badge number. + * + * @param {function(badgeNumber)} success The function to call on success. + * @param {int} success.badgeNumber The current application badge number. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + getBadgeNumber: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.getBadgeNumber', arguments) + callNative(success, failure, "getBadgeNumber") + }, + + /** + * Clears the badge. + * + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + resetBadge: function(success, failure) { + argscheck.checkArgs('FF', 'UAirship.resetBadge', arguments) + callNative(success, failure, "resetBadge") + }, + + /** + * Sets the iOS notification types. Specify the combination of + * badges, sound and alerts that are desired. + * + * @param {notificationType} types specified notification types. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setNotificationTypes: function(types, success, failure) { + argscheck.checkArgs('nFF', 'UAirship.setNotificationTypes', arguments) + callNative(success, failure, "setNotificationTypes", [types]) + }, + + /** + * Sets the iOS presentation options. Specify the combination of + * badges, sound and alerts that are desired. + * + * @param {presentationOptions} types specified presentation options. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setPresentationOptions: function(options, success, failure) { + argscheck.checkArgs('nFF', 'UAirship.setPresentationOptions', arguments) + callNative(success, failure, "setPresentationOptions", [options]) + }, + + /** + * Enables/Disables foreground notifications display on Android. + * + * @param {Boolean} enabled true to enable foreground notifications, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setAndroidForegroundNotificationsEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setAndroidForegroundNotificationsEnabled', arguments) + callNative(success, failure, "setAndroidForegroundNotificationsEnabled", [!!enabled]) + }, + + /** + * Enum for notification types. + * @readonly + * @enum {number} + */ + notificationType: { + none: 0, + badge: 1, + sound: 2, + alert: 4 + }, + + /** + * Enum for presentation options. + * @readonly + * @enum {number} + */ + presentationOptions: { + none: 0, + badge: 1, + sound: 2, + alert: 4 + }, + + // Android only + + /** + * Checks if notification sound is enabled or not. + * + * @param {function(enabled)} success Success callback. + * @param {boolean} success.enabled Flag indicating if sound is enabled or not. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isSoundEnabled: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.isSoundEnabled', arguments) + callNative(success, failure, "isSoundEnabled") + }, + + /** + * Enables or disables notification sound. + * + * @param {Boolean} enabled true to enable sound, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setSoundEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setSoundEnabled', arguments) + callNative(success, failure, "setSoundEnabled", [!!enabled]) + }, + + /** + * Checks if notification vibration is enabled or not. + * + * @param {function(enabled)} success Success callback. + * @param {boolean} success.enabled Flag indicating if vibration is enabled or not. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + isVibrateEnabled: function(success, failure) { + argscheck.checkArgs('fF', 'UAirship.isVibrateEnabled', arguments) + callNative(success, failure, "isVibrateEnabled") + }, + + /** + * Enables or disables notification vibration. + * + * @param {Boolean} enabled true to enable vibration, false to disable. + * @param {function} [success] Success callback. + * @param {function(message)} [failure] Failure callback. + * @param {string} failure.message The error message. + */ + setVibrateEnabled: function(enabled, success, failure) { + argscheck.checkArgs('*FF', 'UAirship.setVibrateEnabled', arguments) + callNative(success, failure, "setVibrateEnabled", [!!enabled]) + } + + } + + +} diff --git a/urbanairship-cordova/www/AirshipRoot.mjs b/urbanairship-cordova/www/AirshipRoot.mjs new file mode 100644 index 00000000..fcd07e31 --- /dev/null +++ b/urbanairship-cordova/www/AirshipRoot.mjs @@ -0,0 +1,123 @@ +/* Copyright Urban Airship and Contributors */ + +import { AirshipActions } from './AirshipActions'; +import { AirshipAnalytics } from './AirshipAnalytics'; +import { AirshipChannel } from './AirshipChannel'; +import { AirshipContact } from './AirshipContact'; +import { AirshipInApp } from './AirshipInApp'; +import { AirshipLocale } from './AirshipLocale'; +import { AirshipMessageCenter } from './AirshipMessageCenter'; +import { AirshipPreferenceCenter } from './AirshipPreferenceCenter'; +import { AirshipPrivacyManager } from './AirshipPrivacyManager'; +import { AirshipPush } from './AirshipPush'; +//import { AirshipConfig, EventTypeMap, EventType } from './types'; +//import { Subscription, UAEventEmitter } from './UAEventEmitter'; + +export class AirshipRoot { + + public readonly actions: AirshipActions; + public readonly analytics: AirshipAnalytics; + public readonly channel: AirshipChannel; + public readonly contact: AirshipContact; + public readonly inApp: AirshipInApp; + public readonly locale: AirshipLocale; + public readonly messageCenter: AirshipMessageCenter; + public readonly preferenceCenter: AirshipPreferenceCenter; + public readonly privacyManager: AirshipPrivacyManager; + public readonly push: AirshipPush; + + constructor(private readonly module: any) { + this.actions = new AirshipActions(module); + this.analytics = new AirshipAnalytics(module); + this.channel = new AirshipChannel(module); + this.contact = new AirshipContact(module); + this.inApp = new AirshipInApp(module); + this.locale = new AirshipLocale(module); + this.messageCenter = new AirshipMessageCenter(module); + this.preferenceCenter = new AirshipPreferenceCenter(module); + this.privacyManager = new AirshipPrivacyManager(module); + this.push = new AirshipPush(module); + this.eventEmitter = new UAEventEmitter(module); + } + + var cordova = require("cordova"), + exec = require("cordova/exec"), + argscheck = require('cordova/argscheck') + + // Argcheck values: + // * : allow anything, + // f : function + // a : array + // d : date + // n : number + // s : string + // o : object + // lowercase = required, uppercase = optional + + // Helper method to call into the native plugin + function callNative(success, failure, name, args) { + args = args || [] + exec(success, failure, "UAirship", name, args) + } + + // Helper method to run an action + function _runAction(actionName, actionValue, success, failure) { + var successWrapper = function(result) { + if (success) { + success(result.value) + } + } + + callNative(successWrapper, failure, "runAction", [actionName, actionValue]) + } + + + function bindDocumentEvent() { + callNative(function(e) { + console.log("Firing document event: " + e.eventType) + cordova.fireDocumentEvent(e.eventType, e.eventData) + }, null, "registerListener") + } + + // document.addEventListener("deviceready", bindDocumentEvent, false) + + + /** + * Initailizes Urban Airship. + * + * The plugin will automatically call takeOff during the next app init in + * order to properly handle incoming push. If takeOff is called multiple times + * in a session, or if the config is different than the previous sesssion, the + * new config will not be used until the next app start. + * + * @param {object} config The Urban Airship config. + * @param {string} config.site Sets the cloud site, must be either EU or US. + * @param {string} config.messageCenterStyleConfig The message center style config file. By default it's "messageCenterStyleConfig" + * @param {object} config.development The Urban Airship development config. + * @param {string} config.development.appKey The development appKey. + * @param {string} config.development.appSecret The development appSecret. + * @param {object} config.production The Urban Airship production config. + * @param {string} config.production.appKey The production appKey. + * @param {string} config.production.appSecret The production appSecret. + */ + public takeOff: function(config, success, failure) { + argscheck.checkArgs("*FF", "UAirship.takeOff", arguments); + callNative(success, failure, "takeOff", [config]); + } + + /** + * Returns the last received deep link. + * + * @param {Boolean} clear true to clear the deep link. + * @param {function(push)} success The function to call on success. + * @param {string} success.deepLink The deep link. + * @param {failureCallback} [failure] The function to call on failure. + * @param {string} failure.message The error message. + */ + public getDeepLink: function(clear, success, failure) { + argscheck.checkArgs('*fF', 'UAirship.getDeepLink', arguments) + callNative(success, failure, "getDeepLink", [!!clear]) + } + + +} diff --git a/urbanairship-hms-cordova/package.json b/urbanairship-hms-cordova/package.json index 8ea8fecc..889923fa 100644 --- a/urbanairship-hms-cordova/package.json +++ b/urbanairship-hms-cordova/package.json @@ -1,6 +1,6 @@ { "name": "urbanairship-hms-cordova", - "version": "14.10.1", + "version": "15.0.0", "description": "Urban Airship HMS Cordova plugin", "cordova": { "id": "urbanairship-hms-cordova", diff --git a/urbanairship-hms-cordova/plugin.xml b/urbanairship-hms-cordova/plugin.xml index 91fa13ba..b9dab98f 100644 --- a/urbanairship-hms-cordova/plugin.xml +++ b/urbanairship-hms-cordova/plugin.xml @@ -1,6 +1,6 @@ @@ -15,7 +15,7 @@ - + diff --git a/urbanairship-hms-cordova/src/android/build-extras.gradle b/urbanairship-hms-cordova/src/android/build-extras.gradle index 655f5f26..08bf60df 100644 --- a/urbanairship-hms-cordova/src/android/build-extras.gradle +++ b/urbanairship-hms-cordova/src/android/build-extras.gradle @@ -5,7 +5,7 @@ repositories { } dependencies { - implementation 'com.urbanairship.android:urbanairship-hms:16.11.1' + implementation 'com.urbanairship.android:urbanairship-hms:17.1.0' implementation 'com.huawei.hms:push:6.3.0.304' }