Created
April 5, 2015 12:04
-
-
Save developerworks/e1e76def3c41f38790c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NativeModules = require('react-native').NativeModules; | |
function RCTQRCodeReaderError(message){ | |
this.message = message; | |
} | |
RCTQRCodeReaderError.prototype = new Error(); | |
module.exports = { | |
RCTQRCodeReaderError: RCTQRCodeReaderError, | |
scan(callback: (error: ?RCTQRCodeReaderError, qrcode: string) => void) { | |
NativeModules.RCTQRCodeReader.scan((error, ret) => { | |
if(error){ | |
return callback(new RCTQRCodeReaderError(error), null); | |
} | |
callback(null, ret) | |
}); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "react-native-qrcode", | |
"version": "0.0.1", | |
"description": "QRCode Reader", | |
"main": "index.ios.js", | |
"author": "Developerworks <[email protected]> (https://github.com/developerworks)", | |
"dependencies": { | |
"react-native": "^0.3.1" | |
}, | |
"devDependencies": { | |
"jest-cli": "0.2.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#import <UIKit/UIKit.h> | |
// | |
//@interface RCTQRCodeReader : UIView | |
// | |
//@end | |
#import <RCTBridgeModule.h> | |
@interface RCTQRCodeReader : NSObject <RCTBridgeModule> | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RCTQRCodeReader.h" | |
#import <RCTBridgeModule.h> | |
#import <RCTConvert.h> | |
#import <RCTLog.h> | |
@implementation RCTQRCodeReader | |
@synthesize bridge = _bridge; | |
- (id) init { | |
self = [super init]; | |
return self; | |
} | |
/** | |
* 返回扫描得到的二维码结果给Javascript Runtime | |
*/ | |
- (void)scan:(RCTResponseSenderBlock)callback { | |
RCT_EXPORT(); | |
// 加载QRCodeReader | |
// 获取结果 | |
// 存储二维码字符串 | |
NSString *result = @"07f14c20-db74-11e4-99b2-000c29d02dc7"; | |
RCTLogError(@"二维码字符串 %@", result); | |
// 返回给Javascript | |
callback(@[[NSNull null], result]); | |
} | |
/** | |
* 在我们的 CalendarManager 示例中,如果我们想传递事件日期给本地模块,我们必须要把它转换成字符串或者数字 | |
*/ | |
//- (void)addEventWithName:(NSString *)name location:(NSString *)location date:(NSInteger)secondsSinceUnixEpoch | |
//{ | |
// RCT_EXPORT(addEvent); | |
// NSDate *date = [NSDate dateWithTimeIntervalSince1970:secondsSinceUnixEpoch]; | |
//} | |
/** | |
* 随着 CalendarManager.addEvent 方法越来越复杂,参数的数量将会增加。某些参数可能是可选的。 | |
* 这时值得考虑改变一点 API 的形式,接受一个事件属性字典,就像这样 | |
*/ | |
//- (void)addEventWithName:(NSString *)name details:(NSDictionary *)details | |
//{ | |
// RCT_EXPORT(addEvent); | |
// // 获取位置参数 | |
// NSString *location = [RCTConvert NSString:details[@"location"]]; // ensure location is a string | |
// // 活期日期参数 | |
// NSInteger *secondsSinceUnixEpoch = [RCTConvert NSInteger:details[@"secondsSinceUnixEpoch"]]; | |
// NSDate *date = [NSDate dateWithTimeIntervalSince1970:secondsSinceUnixEpoch]; | |
//} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment