Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

Waiting for a variable to be assigned before executing code in Objective C

$
0
0

I am trying to write a connection between React Native and Objective C to integrate a native view.

This mostly works at this point, however there's one final step I can't get working - passing back a generated code into React Native. I have the following code:

    RCT_EXPORT_MODULE()    RCT_EXPORT_METHOD(generateCode: (RCTResponseSenderBlock)callback) {     dispatch_async(dispatch_get_main_queue(), ^{          [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"",                                                               PayPalEnvironmentSandbox : @""}];        [self initzero];        [self initone];        [self getUserAuthorizationForProfileSharing];    });    callback(@[[NSNull null], self.code]);}

Ultimate, the getUserAuthorizationForProfileSharing gets to this function:

- (void)sendProfileSharingAuthorizationToServer:(NSDictionary *)authorization {   NSDictionary *response = [authorization objectForKey:@"response"];   NSString *code = [response objectForKey:@"code"];self.code = code;}

This also works and correctly sets the code.

However as far as I can tell, this is all asynchronous. I'm wondering what method I would use to only issue the callback once I get the code property set on the object.

Is there any good way to do this?

EDIT: Here's the stack trace:

2020-05-18 12:24:29.930 [info][tid:com.facebook.react.JavaScript] NATIVE EXCEPTION2020-05-18 12:24:29.930 [info][tid:com.facebook.react.JavaScript] *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]("4   libc++abi.dylib                     0x00007fff50256e97 _ZSt11__terminatePFvvE + 8","5   libc++abi.dylib                     0x00007fff50256e39 _ZSt9terminatev + 41","6   libdispatch.dylib                   0x000000010c12cd5c _dispatch_client_callout + 28","7   libdispatch.dylib                   0x000000010c13ade6 _dispatch_main_queue_callback_4CF + 1500","8   CoreFoundation                      0x00007fff23bd4049 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9")

EDIT: self.code is nil on execution, even when I put it into dispatch_async. I need to ONLY execute the callback AFTER an event has happened


Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>