2017-08-29 95 views
1

试图创建我的第一个npm模块,以确定用户是否在手机上。这是一个React Native应用程序。无论我尝试什么,模块都会返回undefined。 NativeModules总是显示为空对象。反应原生NativeModules空对象

请帮忙!以下是代码的链接。 export default RNOnPhoneCall;index.js将只返回undefined。如何链接ios文件夹中的功能,并将它们导出为index.js?抬头,android尚未最新,只有ios

Link to Github

回答

0

我没有正确导出方法在我的iOS文件。这是解决方案,以及最终项目的链接。

react-native-check-phone-call-status on github

#import "RNCheckPhoneCallStatus.h" 
#import "React/RCTLog.h" 
#import <AVFoundation/AVAudioSession.h> 
#import<CoreTelephony/CTCallCenter.h> 
#import<CoreTelephony/CTCall.h> 

@implementation RNCheckPhoneCallStatus 

RCT_EXPORT_MODULE() 

RCT_EXPORT_METHOD(get:(RCTResponseSenderBlock)callback) 
{ 
    NSString *phoneStatus = @"PHONE_OFF"; 
    CTCallCenter *ctCallCenter = [[CTCallCenter alloc] init]; 
    if (ctCallCenter.currentCalls != nil) 
    { 
     NSArray* currentCalls = [ctCallCenter.currentCalls allObjects]; 
     for (CTCall *call in currentCalls) 
     { 
      if(call.callState == CTCallStateConnected) 
      { 
       phoneStatus = @"PHONE_ON"; 
      } 
     } 
    } 
    callback(@[[NSNull null], phoneStatus]); 
} 

@end 
0

尝试重建项目。我最近面临同样的问题,只是重建解决了它