[React Native] Update native error callback handling

Summary:
This introduces a new `RCTResponseErrorBlock` block type that allows a bridge module writer to call it with an `NSError` instance rather than a dictionary.
This commit is contained in:
Alex Akers
2015-07-07 08:47:23 -07:00
parent 66d3f3c616
commit 3c541ca540
6 changed files with 39 additions and 18 deletions

View File

@@ -10,19 +10,20 @@
#import <AdSupport/ASIdentifierManager.h>
#import "RCTAdSupport.h"
#import "RCTUtils.h"
@implementation RCTAdSupport
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(getAdvertisingId:(RCTResponseSenderBlock)callback
withErrorCallback:(RCTResponseSenderBlock)errorCallback)
withErrorCallback:(RCTResponseErrorBlock)errorCallback)
{
NSUUID *advertisingIdentifier = [ASIdentifierManager sharedManager].advertisingIdentifier;
if (advertisingIdentifier) {
callback(@[advertisingIdentifier.UUIDString]);
} else {
errorCallback(@[@"as_identifier_unavailable"]);
errorCallback(RCTErrorWithMessage(@"Advertising identifier is unavailable."));
}
}