![]() Get let val = await SharedUserDefaults. set( ".example.YourProject", "yourKey", "some string to be stored") import from 'react-native' Ĭonst SharedUserDefaults = NativeModules.SharedUserDefaults In your React Native project, you can now get and set key-value pair to UserDefaults via the native module. NSError *error = Īnd you can use the methods from the native module you've just written. Resolver: (RCTPromiseResolveBlock)resolve RCT_EXPORT_METHOD(get:( NSString *)suiteName NSUserDefaults *shareExtensionDefaults = initWithSuiteName: suiteName] ![]() RCT_EXPORT_METHOD(set:( NSString *)suiteName SharedUserDefaults.m #import #import "SharedUserDefaults.h" SharedUserDefaults I'll name it SharedUserDefaults.h # ifndef SharedUserDefaults_h # define SharedUserDefaults_h # endif #import # if _has_include( ) #import # else #import "RCTBridgeModule.h" # endif SharedUserDefaults : NSObject 2. This is not covered in this post and there are alot of online resources for this topic. In order to achieve that, we need to use UserDefaults with suiteName that starts with group.īefore you proceed, please make sure that you have already created Share Extension and updated App Groups in the Signing & Capabilities. Let's get back and focus on this topic, get and set value in UserDefaults that are accesible in Share Extension. This is a much more complicated implementation and there are much simpler ways to get it done without writing too many native code and that will be for another blog post. So that the Share Extension can perform API call with sufficient data that was set in React Native, and thus giving user a much better experience similar to other natively built apps. The use case for this is to access the data in iOS Share Extension using value set from React Native. In this blog post, I will share the code for a simple RCTBridgeModule that can write/read key-value from React Native.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |