React native 有没有办法在本机iOS代码中调用RCT_EXPORT_方法

React native 有没有办法在本机iOS代码中调用RCT_EXPORT_方法,react-native,react-native-ios,React Native,React Native Ios,我已经创建了RCT\u EXPORT\u方法,我想使用objective c根据某些条件调用该方法 #import <Foundation/Foundation.h> #import "PushNotificationAlert.h" #import <React/RCTLog.h> #import <React/RCTBridgeDelegate.h> #import <UIKit/UIKit.h> #import <MarketingCl

我已经创建了
RCT\u EXPORT\u方法
,我想使用objective c根据某些条件调用该方法

#import <Foundation/Foundation.h>
#import "PushNotificationAlert.h"
#import <React/RCTLog.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <MarketingCloudSDK/MarketingCloudSDK.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "AppDelegate.h"
@implementation PushNotificationAlert

RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent:(NSString *)applicationId accessToken:(NSString *)accessToken marketingCloudServerUrl:(NSString *)marketingCloudServerUrl)
{
    MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
      [mcsdkBuilder sfmc_setApplicationId:applicationId];
  [mcsdkBuilder sfmc_setAccessToken:accessToken];
      [mcsdkBuilder sfmc_setMarketingCloudServerUrl:marketingCloudServerUrl];

      NSError *error = nil;
      BOOL success =
          [[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build]
                                                                     error:&error];
      if (success == YES) {
          dispatch_async(dispatch_get_main_queue(), ^{
            if (@available(iOS 10, *)) {
                // set the UNUserNotificationCenter delegate - the delegate must be set here in
                // didFinishLaunchingWithOptions
                [UNUserNotificationCenter currentNotificationCenter].delegate = self;
                [[UIApplication sharedApplication] registerForRemoteNotifications];

                [[UNUserNotificationCenter currentNotificationCenter]
                    requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
                                                    UNAuthorizationOptionSound |
                                                    UNAuthorizationOptionBadge
                                  completionHandler:^(BOOL granted, NSError *_Nullable error) {
                                    if (error == nil) {
                                        if (granted == YES) {
                                          self.isEnabled = true;
//                                            dispatch_async(dispatch_get_main_queue(), ^{
//                                                           });
                                        } else {
                                          self.isEnabled = false;
                                        }

                                    }
                                  }];
            } else {
  #if __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
                UIUserNotificationSettings *settings = [UIUserNotificationSettings
                    settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound |
                                     UIUserNotificationTypeAlert
                          categories:nil];
                [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  #endif
                [[UIApplication sharedApplication] registerForRemoteNotifications];
            }
          });
      } else {
          //  MarketingCloudSDK sfmc_configure failed
      }
}

RCT_EXPORT_METHOD(findEvents:(RCTResponseSenderBlock)callback)
{
   NSMutableString *deviceToken = ((AppDelegate *)[UIApplication sharedApplication].delegate).deviceToken;
  if(self.isEnabled) {

    if (deviceToken != nil) {
      NSArray *events = [[NSArray alloc] initWithObjects:deviceToken, nil];
      callback(@[[NSNull null], events]);
    }
  } else {
    NSMutableString *deviceToken = ((AppDelegate *)[UIApplication sharedApplication].delegate).deviceToken;
    if (deviceToken != nil) {
      NSArray *events = [[NSArray alloc] initWithObjects:deviceToken, nil];
      callback(@[[NSNull null], events]);
    }
  }
}
@end
#导入
#导入“PushNotificationAlert.h”
#进口
#进口
#进口
#进口
#进口
#进口
#进口
#导入“AppDelegate.h”
@实现PushNotificationAlert
RCT_导出_模块();
RCT_导出方法(addEvent:(NSString*)应用程序ID accessToken:(NSString*)accessToken marketingCloudServerUrl:(NSString*)marketingCloudServerUrl)
{
MarketingCloudSDKConfigBuilder*mcsdkBuilder=[MarketingCloudSDKConfigBuilder new];
[mcsdkBuilder sfmc_setApplicationId:applicationId];
[mcsdkBuilder sfmc_setAccessToken:accessToken];
[mcsdkBuilder sfmc_setMarketingCloudServerUrl:marketingCloudServerUrl];
n错误*错误=nil;
布尔成功=
[[MarketingCloudSDK sharedInstance]sfmc_配置字典:[mcsdkBuilder sfmc_build]
错误:&错误];
如果(成功==是){
dispatch\u async(dispatch\u get\u main\u queue()^{
如果(@可用(iOS 10,*)){
//设置UnuseNotificationCenter委托-必须在此处的中设置该委托
//使用选项完成启动
[UnuseNotificationCenter currentNotificationCenter]。委托=自身;
[[UIApplication sharedApplication]注册表项的删除];
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:UNAuthorizationOptionAlert|
未授权选项声音|
未授权选择徽章
completionHandler:^(BOOL已授予,n错误*\u可为空错误){
如果(错误==nil){
如果(已授予==是){
self.isEnabled=true;
//dispatch\u async(dispatch\u get\u main\u queue()^{
//                                                           });
}否则{
self.isEnabled=false;
}
}
}];
}否则{
#如果IPHONE操作系统版本最低要求<100000
UIUserNotificationSettings*设置=[UIUserNotificationSettings]
设置类型:UIUserNotificationTypeBadge | UIUserNotificationTypeSound|
UIUserNotificationTypeAlert
类别:无;;
[[UIApplication sharedApplication]注册表通知设置:设置];
#恩迪夫
[[UIApplication sharedApplication]注册表项的删除];
}
});
}否则{
//MarketingCloudSDK sfmc_配置失败
}
}
RCT\u导出\u方法(findEvents:(RCTresResponseSenderBlock)回调)
{
NSMutableString*deviceToken=((AppDelegate*)[UIApplication sharedApplication].delegate).deviceToken;
如果(自我激活){
如果(deviceToken!=无){
NSArray*事件=[[NSArray alloc]initWithObjects:deviceToken,nil];
回调(@[[NSNull],null],事件]);
}
}否则{
NSMutableString*deviceToken=((AppDelegate*)[UIApplication sharedApplication].delegate).deviceToken;
如果(deviceToken!=无){
NSArray*事件=[[NSArray alloc]initWithObjects:deviceToken,nil];
回调(@[[NSNull],null],事件]);
}
}
}
@结束
当授予权限时,如何调用
RCT\u EXPORT\u方法