but I noticed that my bridge variable is zero when I call it from another method. I believe that this is due to the fact that the bridge is set only when the bridge method is called from javascript. I tried everything from creating a delegate to creating a SingleTon class. None of the above work, and I can’t understand why it is only available in the method that I called from Javascript. Here is my class
helper.h
#import "RCTBridge.h"
#import "AppDelegate.h"
#import "RCTEventEmitter.h"
@interface Helper : RCTEventEmitter <RCTBridgeModule>
-(void) auth;
@end
Here is my .m file: Helper.m
#import "AppDelegate.h"
#import "Helper.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
@implementation Helper
RCT_EXPORT_MODULE();
@synthesize bridge = _bridge;
- (NSArray<NSString *> *)supportedEvents {
return @[@"SpotifyHelper"];
}
RCT_EXPORT_METHOD(auth)
{
[self.bridge.eventDispatcher sendDeviceEventWithName:@"SpotifyHelper" body:@{@"Login": @true}];
printf("Auth");
}
RCT_EXPORT_METHOD(play:(NSString *) uri first: id)
{
AppDelegate *appDelegate = [[AppDelegate alloc] init];
[appDelegate play:uri second:id];
}
@end
I call this method from within my delegate as follows:
[[AppDelegate alloc] init] auth]
That is why I believe that it is not initialized. I'm not sure how to get the RCTBridge variable so that it is not null. Any help?