Alex Akers 3c541ca540 [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.
2015-07-07 08:54:05 -08:00

37 lines
1.1 KiB
Objective-C

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <AdSupport/ASIdentifierManager.h>
#import "RCTAdSupport.h"
#import "RCTUtils.h"
@implementation RCTAdSupport
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(getAdvertisingId:(RCTResponseSenderBlock)callback
withErrorCallback:(RCTResponseErrorBlock)errorCallback)
{
NSUUID *advertisingIdentifier = [ASIdentifierManager sharedManager].advertisingIdentifier;
if (advertisingIdentifier) {
callback(@[advertisingIdentifier.UUIDString]);
} else {
errorCallback(RCTErrorWithMessage(@"Advertising identifier is unavailable."));
}
}
RCT_EXPORT_METHOD(getAdvertisingTrackingEnabled:(RCTResponseSenderBlock)callback
withErrorCallback:(__unused RCTResponseSenderBlock)errorCallback)
{
callback(@[@([ASIdentifierManager sharedManager].advertisingTrackingEnabled)]);
}
@end