diff --git a/android/src/main/java/com/mindboxsdk/MindboxSdkModule.kt b/android/src/main/java/com/mindboxsdk/MindboxSdkModule.kt index 45ce737..be9237c 100644 --- a/android/src/main/java/com/mindboxsdk/MindboxSdkModule.kt +++ b/android/src/main/java/com/mindboxsdk/MindboxSdkModule.kt @@ -228,7 +228,7 @@ class MindboxSdkModule(private val reactContext: ReactApplicationContext) : Reac } @ReactMethod - fun updateNotificationPermissionStatus(granted: Boolean) { + fun refreshNotificationPermissionStatus() { Mindbox.updateNotificationPermissionStatus( context = reactApplicationContext.applicationContext, ) diff --git a/example/exampleApp/ios/AppDelegate.swift b/example/exampleApp/ios/AppDelegate.swift index 478f6cb..27c3423 100644 --- a/example/exampleApp/ios/AppDelegate.swift +++ b/example/exampleApp/ios/AppDelegate.swift @@ -97,7 +97,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD extension AppDelegate: RCTBridgeDelegate { func sourceURL(for bridge: RCTBridge!) -> URL! { #if DEBUG - return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource: nil) + return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") #else return Bundle.main.url(forResource: "main", withExtension: "jsbundle") #endif diff --git a/example/exampleApp/ios/exampleApp.xcodeproj/project.pbxproj b/example/exampleApp/ios/exampleApp.xcodeproj/project.pbxproj index 464c5ca..a267e63 100644 --- a/example/exampleApp/ios/exampleApp.xcodeproj/project.pbxproj +++ b/example/exampleApp/ios/exampleApp.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 3ACCD5252B736C0000C94F45 /* UserNotificationsUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3ACCD5242B736C0000C94F45 /* UserNotificationsUI.framework */; }; 3ACCD5282B736C0000C94F45 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ACCD5272B736C0000C94F45 /* NotificationViewController.swift */; }; 3ACCD52F2B736C0000C94F45 /* MindboxNotificationContentExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 3ACCD5212B736C0000C94F45 /* MindboxNotificationContentExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 47632DE92EBB68C1005CF203 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 47632DE82EBB68C1005CF203 /* PrivacyInfo.xcprivacy */; }; 6FA2F0A6E649B5D37A50E5DF /* libPods-exampleApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 225AB1FB2853D87400D56406 /* libPods-exampleApp.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; D12DD691CE76549C9A289F4A /* libPods-exampleApp-MindboxNotificationContentExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F94D0E16F83CA4229F8935E5 /* libPods-exampleApp-MindboxNotificationContentExtension.a */; }; @@ -85,6 +86,7 @@ 3ACCD5332B736C3600C94F45 /* MindboxNotificationContentExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MindboxNotificationContentExtension.entitlements; sourceTree = ""; }; 443E0C92268BE125C44414DB /* Pods-exampleApp-MindboxNotificationServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-exampleApp-MindboxNotificationServiceExtension.debug.xcconfig"; path = "Target Support Files/Pods-exampleApp-MindboxNotificationServiceExtension/Pods-exampleApp-MindboxNotificationServiceExtension.debug.xcconfig"; sourceTree = ""; }; 47152D5D7BA14904B8BB519A /* Pods-exampleApp-MindboxNotificationContentExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-exampleApp-MindboxNotificationContentExtension.release.xcconfig"; path = "Target Support Files/Pods-exampleApp-MindboxNotificationContentExtension/Pods-exampleApp-MindboxNotificationContentExtension.release.xcconfig"; sourceTree = ""; }; + 47632DE82EBB68C1005CF203 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = exampleApp/PrivacyInfo.xcprivacy; sourceTree = ""; }; 47AD8F18AB85B027D3981AE3 /* Pods-exampleApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-exampleApp.debug.xcconfig"; path = "Target Support Files/Pods-exampleApp/Pods-exampleApp.debug.xcconfig"; sourceTree = ""; }; 52276FFC6E12FB80FA062002 /* libPods-exampleApp-exampleAppTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-exampleApp-exampleAppTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 6A5E00695C40D3AAF012A013 /* Pods-exampleApp-MindboxNotificationContentExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-exampleApp-MindboxNotificationContentExtension.debug.xcconfig"; path = "Target Support Files/Pods-exampleApp-MindboxNotificationContentExtension/Pods-exampleApp-MindboxNotificationContentExtension.debug.xcconfig"; sourceTree = ""; }; @@ -130,6 +132,7 @@ 13B07FAE1A68108700A75B9A /* exampleApp */ = { isa = PBXGroup; children = ( + 47632DE82EBB68C1005CF203 /* PrivacyInfo.xcprivacy */, 3A88FC0B2B6CEE180046E687 /* exampleApp.entitlements */, 13B07FB51A68108700A75B9A /* Images.xcassets */, 13B07FB61A68108700A75B9A /* Info.plist */, @@ -348,6 +351,7 @@ buildActionMask = 2147483647; files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, + 47632DE92EBB68C1005CF203 /* PrivacyInfo.xcprivacy in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -393,14 +397,10 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-frameworks.sh\"\n"; @@ -414,14 +414,10 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-resources-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-exampleApp/Pods-exampleApp-resources.sh\"\n"; @@ -435,14 +431,10 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationContentExtension/Pods-exampleApp-MindboxNotificationContentExtension-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationContentExtension/Pods-exampleApp-MindboxNotificationContentExtension-resources-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationContentExtension/Pods-exampleApp-MindboxNotificationContentExtension-resources.sh\"\n"; @@ -500,14 +492,10 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationServiceExtension/Pods-exampleApp-MindboxNotificationServiceExtension-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationServiceExtension/Pods-exampleApp-MindboxNotificationServiceExtension-resources-${CONFIGURATION}-output-files.xcfilelist", ); - outputPaths = ( - ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-exampleApp-MindboxNotificationServiceExtension/Pods-exampleApp-MindboxNotificationServiceExtension-resources.sh\"\n"; @@ -610,6 +598,7 @@ PRODUCT_BUNDLE_IDENTIFIER = mindbox.RN.Example; PRODUCT_NAME = exampleApp; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OBJC_BRIDGING_HEADER = "exampleApp-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -643,6 +632,7 @@ PRODUCT_BUNDLE_IDENTIFIER = mindbox.RN.Example; PRODUCT_NAME = exampleApp; PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; SWIFT_OBJC_BRIDGING_HEADER = "exampleApp-Bridging-Header.h"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -833,6 +823,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = "$(inherited)"; + CC = ""; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_CXX_LIBRARY = "libc++"; @@ -860,6 +851,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + CXX = ""; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386; @@ -879,6 +871,8 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.4; + LD = ""; + LDPLUSPLUS = ""; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", @@ -898,9 +892,13 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; USE_HERMES = true; }; name = Debug; @@ -909,6 +907,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = "$(inherited)"; + CC = ""; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_CXX_LIBRARY = "libc++"; @@ -936,6 +935,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + CXX = ""; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386; @@ -948,6 +948,8 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.4; + LD = ""; + LDPLUSPLUS = ""; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", @@ -966,7 +968,10 @@ "-DFOLLY_USE_LIBCPP=1", "-DFOLLY_CFG_NO_COROUTINES=1", ); - OTHER_LDFLAGS = "$(inherited) "; + OTHER_LDFLAGS = ( + "$(inherited)", + " ", + ); REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; USE_HERMES = true; diff --git a/example/exampleApp/ios/exampleApp/PrivacyInfo.xcprivacy b/example/exampleApp/ios/exampleApp/PrivacyInfo.xcprivacy new file mode 100644 index 0000000..01ce452 --- /dev/null +++ b/example/exampleApp/ios/exampleApp/PrivacyInfo.xcprivacy @@ -0,0 +1,48 @@ + + + + + NSPrivacyTracking + + NSPrivacyTrackingDomains + + NSPrivacyCollectedDataTypes + + + NSPrivacyCollectedDataType + NSPrivacyCollectedDataTypeOtherDiagnosticData + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + NSPrivacyCollectedDataType + NSPrivacyCollectedDataTypeDeviceID + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeProductPersonalization + + + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryUserDefaults + NSPrivacyAccessedAPITypeReasons + + CA92.1 + + + + + diff --git a/example/exampleApp/src/screens/HomeScreen.tsx b/example/exampleApp/src/screens/HomeScreen.tsx index 39ba02f..17c52e4 100644 --- a/example/exampleApp/src/screens/HomeScreen.tsx +++ b/example/exampleApp/src/screens/HomeScreen.tsx @@ -10,7 +10,7 @@ import { chooseInappCallback, RegisterInappCallback } from '../utils/InAppCallba const configuration = { domain: 'api.mindbox.ru', // Set your endpoints system name for ios and android below - endpointId: Platform.OS === 'ios' ? '' : '', + endpointId: Platform.OS === 'ios' ? 'Mpush-test.IosRnExample' : 'Mpush-test.AndroidRnExample', subscribeCustomerIfCreated: true, shouldCreateCustomer: true, } @@ -26,18 +26,27 @@ const HomeScreen = () => { const [sdkVersion, setSdkVersion] = useState('Empty') useEffect(() => { - requestNotificationPermission() - appInitializationCallback() // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#setloglevel-since-280 MindboxSdk.setLogLevel(LogLevel.DEBUG) + + requestNotificationPermission() + appInitializationCallback() + // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#getdeviceuuid - MindboxSdk.getDeviceUUID(setDeviceUUID) - // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#gettoken - MindboxSdk.getTokens(setToken) - // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#getsdkversion-since-280 - MindboxSdk.getSdkVersion((version) => { - setSdkVersion(version) + MindboxSdk.getDeviceUUID((uuid: string) => { + setDeviceUUID(uuid) + + // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#gettoken + MindboxSdk.getTokens((t: string) => { + setToken(t) + + // https://developers.mindbox.ru/docs/%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D1%8B-react-natice-sdk#getsdkversion-since-280 + MindboxSdk.getSdkVersion((version) => { + setSdkVersion(version) + }) + }) }) + // https://developers.mindbox.ru/docs/in-app#react-native chooseInappCallback(RegisterInappCallback.DEFAULT) }, [appInitializationCallback]) diff --git a/example/exampleApp/src/utils/RequestPermission.tsx b/example/exampleApp/src/utils/RequestPermission.tsx index 23ce3be..91771fa 100644 --- a/example/exampleApp/src/utils/RequestPermission.tsx +++ b/example/exampleApp/src/utils/RequestPermission.tsx @@ -3,12 +3,6 @@ import MindboxSdk from 'mindbox-sdk' export const requestNotificationPermission = async () => { requestNotifications(['alert', 'sound']).then(({ status, settings }) => { - if (status === RESULTS.GRANTED) { - console.log('Permission granted') - MindboxSdk.updateNotificationPermissionStatus(true) - } else { - console.log('Permission not granted') - MindboxSdk.updateNotificationPermissionStatus(false) - } + MindboxSdk.refreshNotificationPermissionStatus() }) } diff --git a/ios/MindboxSdk.m b/ios/MindboxSdk.m index d24452e..2ebf228 100644 --- a/ios/MindboxSdk.m +++ b/ios/MindboxSdk.m @@ -22,7 +22,7 @@ @interface RCT_EXTERN_MODULE(MindboxSdk, NSObject) RCT_EXTERN_METHOD(pushDelivered:(NSString)uniqKey) -RCT_EXTERN_METHOD(updateNotificationPermissionStatus:(BOOL)granted) +RCT_EXTERN_METHOD(refreshNotificationPermissionStatus) RCT_EXTERN_METHOD(writeNativeLog:(NSString)message level:(NSInteger)level) diff --git a/ios/MindboxSdk.swift b/ios/MindboxSdk.swift index c2de7ff..49a39a3 100644 --- a/ios/MindboxSdk.swift +++ b/ios/MindboxSdk.swift @@ -193,8 +193,8 @@ class MindboxSdk: NSObject { } @objc - func updateNotificationPermissionStatus(_ granted: Bool) { - Mindbox.shared.notificationsRequestAuthorization(granted: granted) + func refreshNotificationPermissionStatus() { + Mindbox.shared.refreshNotificationPermissionStatus() } @objc diff --git a/src/index.tsx b/src/index.tsx index a453d1c..28264da 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -434,12 +434,27 @@ class MindboxSdkClass { } /** - * This method is used to inform sdk when the notification permission status changed + * This method is kept for backward compatibility. The `granted` argument is ignored. + * The SDK reads the current system authorization status and, if it differs + * from the last known value, sends an update to the backend. * * @param granted current permission status + * @deprecated Use `refreshNotificationPermissionStatus()` instead. */ public updateNotificationPermissionStatus(granted: Boolean) { - return MindboxSdkNative.updateNotificationPermissionStatus(granted) + console.warn(`updateNotificationPermissionStatus(granted=${String(granted)}) is deprecated. Use refreshNotificationPermissionStatus instead.`) + return MindboxSdkNative.refreshNotificationPermissionStatus() + } + + /** + * Checks the current system authorization status for push notifications + * and reports any changes to Mindbox. + * + * @example + * MindboxSdk.refreshNotificationPermissionStatus() + */ + public refreshNotificationPermissionStatus() { + return MindboxSdkNative.refreshNotificationPermissionStatus() } /**