├── BeaconBroadcast.h ├── BeaconBroadcast.m ├── BeaconBroadcast.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── BeaconBroadcast.xcscmblueprint │ └── xcuserdata │ │ └── 9fox.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── 9fox.xcuserdatad │ └── xcschemes │ ├── BeaconBroadcast.xcscheme │ └── xcschememanagement.plist ├── LICENSE ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── ibeacon │ └── simulator │ ├── BeaconBroadcast.java │ └── BeaconBroadcastPackage.java ├── index.android.js ├── index.ios.js └── package.json /BeaconBroadcast.h: -------------------------------------------------------------------------------- 1 | #import "RCTBridgeModule.h" 2 | 3 | #import 4 | #import 5 | 6 | @interface BeaconBroadcast : NSObject 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /BeaconBroadcast.m: -------------------------------------------------------------------------------- 1 | #import "BeaconBroadcast.h" 2 | 3 | @interface BeaconBroadcast() 4 | 5 | @property (nonatomic, strong) CLLocationManager *locationManager; 6 | @property (nonatomic, strong) CLBeaconRegion *beaconRegion; 7 | @property (nonatomic, strong) CBPeripheralManager *peripheralManager; 8 | 9 | @end 10 | 11 | @implementation BeaconBroadcast 12 | 13 | RCT_EXPORT_MODULE() 14 | 15 | RCT_EXPORT_METHOD(startSharedAdvertisingBeaconWithString:(NSString *)uuid major:(int)major minor:(int)minor identifier:(NSString *)identifier) 16 | { 17 | [[BeaconBroadcast sharedInstance] startAdvertisingBeaconWithString: uuid major: major minor: minor identifier: identifier]; 18 | } 19 | 20 | RCT_EXPORT_METHOD(stopSharedAdvertisingBeacon) 21 | { 22 | [[BeaconBroadcast sharedInstance] stopAdvertisingBeacon]; 23 | } 24 | 25 | #pragma mark - Common 26 | 27 | + (id)sharedInstance 28 | { 29 | // structure used to test whether the block has completed or not 30 | static dispatch_once_t p = 0; 31 | 32 | // initialize sharedObject as nil (first call only) 33 | __strong static id _sharedObject = nil; 34 | 35 | // executes a block object once and only once for the lifetime of an application 36 | dispatch_once(&p, ^{ 37 | _sharedObject = [[self alloc] init]; 38 | }); 39 | 40 | // returns the same object each time 41 | return _sharedObject; 42 | } 43 | 44 | - (void)startAdvertisingBeaconWithString:(NSString *)uuid major:(int)major minor:(int)minor identifier:(NSString *)identifier 45 | { 46 | NSLog(@"Turning on advertising..."); 47 | 48 | [self createBeaconRegionWithString:uuid major:major minor:minor identifier:identifier]; 49 | 50 | if (!self.peripheralManager) 51 | self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil]; 52 | 53 | [self turnOnAdvertising]; 54 | } 55 | 56 | - (void)stopAdvertisingBeacon 57 | { 58 | if ([self.peripheralManager isAdvertising]) { 59 | [self.peripheralManager stopAdvertising]; 60 | } 61 | 62 | NSLog(@"Turned off advertising."); 63 | } 64 | 65 | - (void)createBeaconRegionWithString:(NSString *)uuid major:(int)major minor:(int)minor identifier:(NSString *)identifier 66 | { 67 | // if (self.beaconRegion) 68 | // return; 69 | 70 | NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; 71 | self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID major:major minor:minor identifier:identifier]; 72 | self.beaconRegion.notifyEntryStateOnDisplay = YES; 73 | } 74 | 75 | - (void)createLocationManager 76 | { 77 | if (!self.locationManager) { 78 | self.locationManager = [[CLLocationManager alloc] init]; 79 | self.locationManager.delegate = self; 80 | } 81 | } 82 | 83 | #pragma mark - Beacon advertising 84 | 85 | - (void)turnOnAdvertising 86 | { 87 | if (self.peripheralManager.state != CBPeripheralManagerStatePoweredOn) { 88 | NSLog(@"Peripheral manager is off."); 89 | return; 90 | } 91 | 92 | time_t t; 93 | srand((unsigned) time(&t)); 94 | 95 | UInt16 major = [self.beaconRegion.major unsignedShortValue]; 96 | UInt16 minor = [self.beaconRegion.minor unsignedShortValue]; 97 | 98 | NSLog(@"Minor HHAHHAHAHHAHAHAHHAHAHHA: %d", minor); 99 | 100 | 101 | CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:self.beaconRegion.proximityUUID 102 | major: major 103 | minor: minor 104 | identifier:self.beaconRegion.identifier]; 105 | NSDictionary *beaconPeripheralData = [region peripheralDataWithMeasuredPower:nil]; 106 | [self.peripheralManager startAdvertising:beaconPeripheralData]; 107 | 108 | NSLog(@"Turning on advertising for region: %@.", region); 109 | } 110 | 111 | #pragma mark - Beacon advertising delegate methods 112 | - (void)peripheralManagerDidStartAdvertising:(CBPeripheralManager *)peripheralManager error:(NSError *)error 113 | { 114 | if (error) { 115 | NSLog(@"Couldn't turn on advertising: %@", error); 116 | return; 117 | } 118 | 119 | if (peripheralManager.isAdvertising) { 120 | NSLog(@"Turned on advertising."); 121 | } 122 | } 123 | 124 | - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheralManager 125 | { 126 | if (peripheralManager.state != CBPeripheralManagerStatePoweredOn) { 127 | NSLog(@"Peripheral manager is off."); 128 | return; 129 | } 130 | 131 | NSLog(@"Peripheral manager is on."); 132 | [self turnOnAdvertising]; 133 | } 134 | 135 | 136 | @end 137 | -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 13BE3DEE1AC21097009241FE /* BeaconBroadcast.m in Sources */ = {isa = PBXBuildFile; fileRef = 13BE3DED1AC21097009241FE /* BeaconBroadcast.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libBeaconBroadcast.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBeaconBroadcast.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 13BE3DEC1AC21097009241FE /* BeaconBroadcast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeaconBroadcast.h; sourceTree = ""; }; 28 | 13BE3DED1AC21097009241FE /* BeaconBroadcast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BeaconBroadcast.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 134814211AA4EA7D00B7C361 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 134814201AA4EA6300B7C361 /* libBeaconBroadcast.a */, 46 | ); 47 | name = Products; 48 | sourceTree = ""; 49 | }; 50 | 58B511D21A9E6C8500147676 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 13BE3DEC1AC21097009241FE /* BeaconBroadcast.h */, 54 | 13BE3DED1AC21097009241FE /* BeaconBroadcast.m */, 55 | 134814211AA4EA7D00B7C361 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | 58B511DA1A9E6C8500147676 /* BeaconBroadcast */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "BeaconBroadcast" */; 65 | buildPhases = ( 66 | 58B511D71A9E6C8500147676 /* Sources */, 67 | 58B511D81A9E6C8500147676 /* Frameworks */, 68 | 58B511D91A9E6C8500147676 /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = BeaconBroadcast; 75 | productName = RCTDataManager; 76 | productReference = 134814201AA4EA6300B7C361 /* libBeaconBroadcast.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | 58B511D31A9E6C8500147676 /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 0610; 86 | ORGANIZATIONNAME = Facebook; 87 | TargetAttributes = { 88 | 58B511DA1A9E6C8500147676 = { 89 | CreatedOnToolsVersion = 6.1.1; 90 | }; 91 | }; 92 | }; 93 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "BeaconBroadcast" */; 94 | compatibilityVersion = "Xcode 3.2"; 95 | developmentRegion = English; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | en, 99 | ); 100 | mainGroup = 58B511D21A9E6C8500147676; 101 | productRefGroup = 58B511D21A9E6C8500147676; 102 | projectDirPath = ""; 103 | projectRoot = ""; 104 | targets = ( 105 | 58B511DA1A9E6C8500147676 /* BeaconBroadcast */, 106 | ); 107 | }; 108 | /* End PBXProject section */ 109 | 110 | /* Begin PBXSourcesBuildPhase section */ 111 | 58B511D71A9E6C8500147676 /* Sources */ = { 112 | isa = PBXSourcesBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | 13BE3DEE1AC21097009241FE /* BeaconBroadcast.m in Sources */, 116 | ); 117 | runOnlyForDeploymentPostprocessing = 0; 118 | }; 119 | /* End PBXSourcesBuildPhase section */ 120 | 121 | /* Begin XCBuildConfiguration section */ 122 | 58B511ED1A9E6C8500147676 /* Debug */ = { 123 | isa = XCBuildConfiguration; 124 | buildSettings = { 125 | ALWAYS_SEARCH_USER_PATHS = NO; 126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 127 | CLANG_CXX_LIBRARY = "libc++"; 128 | CLANG_ENABLE_MODULES = YES; 129 | CLANG_ENABLE_OBJC_ARC = YES; 130 | CLANG_WARN_BOOL_CONVERSION = YES; 131 | CLANG_WARN_CONSTANT_CONVERSION = YES; 132 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 133 | CLANG_WARN_EMPTY_BODY = YES; 134 | CLANG_WARN_ENUM_CONVERSION = YES; 135 | CLANG_WARN_INT_CONVERSION = YES; 136 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 137 | CLANG_WARN_UNREACHABLE_CODE = YES; 138 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 139 | COPY_PHASE_STRIP = NO; 140 | ENABLE_STRICT_OBJC_MSGSEND = YES; 141 | GCC_C_LANGUAGE_STANDARD = gnu99; 142 | GCC_DYNAMIC_NO_PIC = NO; 143 | GCC_OPTIMIZATION_LEVEL = 0; 144 | GCC_PREPROCESSOR_DEFINITIONS = ( 145 | "DEBUG=1", 146 | "$(inherited)", 147 | ); 148 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 149 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 150 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 151 | GCC_WARN_UNDECLARED_SELECTOR = YES; 152 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 153 | GCC_WARN_UNUSED_FUNCTION = YES; 154 | GCC_WARN_UNUSED_VARIABLE = YES; 155 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 156 | MTL_ENABLE_DEBUG_INFO = YES; 157 | ONLY_ACTIVE_ARCH = YES; 158 | SDKROOT = iphoneos; 159 | }; 160 | name = Debug; 161 | }; 162 | 58B511EE1A9E6C8500147676 /* Release */ = { 163 | isa = XCBuildConfiguration; 164 | buildSettings = { 165 | ALWAYS_SEARCH_USER_PATHS = NO; 166 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 167 | CLANG_CXX_LIBRARY = "libc++"; 168 | CLANG_ENABLE_MODULES = YES; 169 | CLANG_ENABLE_OBJC_ARC = YES; 170 | CLANG_WARN_BOOL_CONVERSION = YES; 171 | CLANG_WARN_CONSTANT_CONVERSION = YES; 172 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 173 | CLANG_WARN_EMPTY_BODY = YES; 174 | CLANG_WARN_ENUM_CONVERSION = YES; 175 | CLANG_WARN_INT_CONVERSION = YES; 176 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 177 | CLANG_WARN_UNREACHABLE_CODE = YES; 178 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 179 | COPY_PHASE_STRIP = YES; 180 | ENABLE_NS_ASSERTIONS = NO; 181 | ENABLE_STRICT_OBJC_MSGSEND = YES; 182 | GCC_C_LANGUAGE_STANDARD = gnu99; 183 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 184 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 185 | GCC_WARN_UNDECLARED_SELECTOR = YES; 186 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 187 | GCC_WARN_UNUSED_FUNCTION = YES; 188 | GCC_WARN_UNUSED_VARIABLE = YES; 189 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 190 | MTL_ENABLE_DEBUG_INFO = NO; 191 | SDKROOT = iphoneos; 192 | VALIDATE_PRODUCT = YES; 193 | }; 194 | name = Release; 195 | }; 196 | 58B511F01A9E6C8500147676 /* Debug */ = { 197 | isa = XCBuildConfiguration; 198 | buildSettings = { 199 | HEADER_SEARCH_PATHS = ( 200 | "$(inherited)", 201 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 202 | "$(SRCROOT)/../../React/**", 203 | "$(SRCROOT)/../../node_modules/react-native/React/**", 204 | ); 205 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 206 | OTHER_LDFLAGS = "-ObjC"; 207 | PRODUCT_NAME = BeaconBroadcast; 208 | SKIP_INSTALL = YES; 209 | }; 210 | name = Debug; 211 | }; 212 | 58B511F11A9E6C8500147676 /* Release */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | HEADER_SEARCH_PATHS = ( 216 | "$(inherited)", 217 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 218 | "$(SRCROOT)/../../React/**", 219 | "$(SRCROOT)/../../node_modules/react-native/React/**", 220 | ); 221 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 222 | OTHER_LDFLAGS = "-ObjC"; 223 | PRODUCT_NAME = BeaconBroadcast; 224 | SKIP_INSTALL = YES; 225 | }; 226 | name = Release; 227 | }; 228 | /* End XCBuildConfiguration section */ 229 | 230 | /* Begin XCConfigurationList section */ 231 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "BeaconBroadcast" */ = { 232 | isa = XCConfigurationList; 233 | buildConfigurations = ( 234 | 58B511ED1A9E6C8500147676 /* Debug */, 235 | 58B511EE1A9E6C8500147676 /* Release */, 236 | ); 237 | defaultConfigurationIsVisible = 0; 238 | defaultConfigurationName = Release; 239 | }; 240 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "BeaconBroadcast" */ = { 241 | isa = XCConfigurationList; 242 | buildConfigurations = ( 243 | 58B511F01A9E6C8500147676 /* Debug */, 244 | 58B511F11A9E6C8500147676 /* Release */, 245 | ); 246 | defaultConfigurationIsVisible = 0; 247 | defaultConfigurationName = Release; 248 | }; 249 | /* End XCConfigurationList section */ 250 | }; 251 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 252 | } 253 | -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/project.xcworkspace/xcshareddata/BeaconBroadcast.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "957A562EB960C279C6B643314680A7CF2F130FA6", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "957A562EB960C279C6B643314680A7CF2F130FA6" : 9223372036854775807, 8 | "A2674DB35A98BF2E331DBD081239FEE44C3D779D" : 9223372036854775807 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "688D6D3B-444F-46A7-9154-094A3463B64B", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "957A562EB960C279C6B643314680A7CF2F130FA6" : "beaconbroadcast\/", 13 | "A2674DB35A98BF2E331DBD081239FEE44C3D779D" : ".." 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "BeaconBroadcast", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "BeaconBroadcast.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/philipheinser\/beaconbroadcast.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "957A562EB960C279C6B643314680A7CF2F130FA6" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "gitlab.com:paywithflow\/merchant_app.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A2674DB35A98BF2E331DBD081239FEE44C3D779D" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/project.xcworkspace/xcuserdata/9fox.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamtran29/react-native-ibeacon-simulator/f33c5cd2936ae8ed2d6081553e5b7049a78b1c06/BeaconBroadcast.xcodeproj/project.xcworkspace/xcuserdata/9fox.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/xcuserdata/9fox.xcuserdatad/xcschemes/BeaconBroadcast.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /BeaconBroadcast.xcodeproj/xcuserdata/9fox.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BeaconBroadcast.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 58B511DA1A9E6C8500147676 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 William Tran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | React Native Module that broadcasts an iBeacon uuid. 2 | 3 | # Setup 4 | 5 | `npm i --save react-native-ibeacon-simulator` 6 | 7 | `react-native link` 8 | 9 | Import in your project: 10 | 11 | `import BeaconBroadcast from 'react-native-ibeacon-simulator'` 12 | 13 | # API 14 | 15 | Start iBeacon on device: 16 | 17 | ### uuid: String 18 | 19 | You can get from here http://openuuid.net/ 20 | 21 | ### identifier: String 22 | 23 | ### minor and major: 24 | 25 | are integer values between 0 and 65535. 26 | 27 | ### Start Broadcasting iBeacon: 28 | 29 | `BeaconBroadcast.startAdvertisingBeaconWithString(uuid, identifier, major, minor)` 30 | 31 | ### Stop Broadcasting iBeacon: 32 | 33 | `BeaconBroadcast.stopAdvertisingBeacon()` 34 | 35 | # iOS 36 | 37 | ``` 38 | BeaconBroadcast.stopAdvertisingBeacon() 39 | BeaconBroadcast.startAdvertisingBeaconWithString(uuid, identifier, major, minor) 40 | ``` 41 | 42 | # Android 43 | 44 | ``` 45 | BeaconBroadcast.checkTransmissionSupported() 46 | .then(() => { 47 | BeaconBroadcast.stopAdvertisingBeacon() 48 | BeaconBroadcast.startAdvertisingBeaconWithString(uuid, identifier, major, minor) 49 | }) 50 | .catch((e) => { 51 | /* handle return errors */ 52 | - NOT_SUPPORTED_MIN_SDK 53 | - NOT_SUPPORTED_BLE 54 | - DEPRECATED_NOT_SUPPORTED_MULTIPLE_ADVERTISEMENTS 55 | - NOT_SUPPORTED_CANNOT_GET_ADVERTISER 56 | - NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS 57 | }) 58 | ``` 59 | 60 | ## Known supported devices 61 | 62 | Non-exhaustive list of devices where BLE advertising is known to work. 63 | [Brackets] indicate variations besides the base model. 64 | 65 | - Phones and tablets 66 | - Google Pixel [XL], Pixel C, Nexus 6P, 6, 5X, 9, patched Nexus 5 67 | - Alcatel One Touch Idol 3 [Dual SIM], Fierce XL 68 | - Asus Zenfone 2 [Laser], Zenpad 8 69 | - Blackberry Priv 70 | - HTC 10, One M9, Desire (530/626s/820) 71 | - Huawei Ascend Y550, Honor 5X, Union 72 | - Lenovo K3 Note, Vibe P1m, Vibe K4 Note 73 | - LG: 74 | * G5, G4 [Stylus], G3, G Flex2, G Vista 2 75 | * V10, K10, L Bello, Lancet, Leon, Magna, Optimus Zone 3, Spirit, Tribute 5 76 | - Moto X Play, X Style, X2, G2, G3, G4, Z Droid, Droid Turbo 2 77 | - Nextbit Robin 78 | - OnePlus 2, 3 79 | - OPPO A33f 80 | - Samsung Galaxy: 81 | * S7 [Edge] - up to 8 concurrent running BLE advertisers 82 | * S6 [Active/Edge/Edge Plus], S5 [Active/Neo] 83 | * Note 5, Note Edge, Note 4 84 | * Tab S2 (8.0/9.7), Tab S (8.4/10.5), Note Pro, Tab A 9.7, Tab E 85 | * A5 2016 [Duos] 86 | * J5, J3 Duos 87 | * Alpha, Core Prime, Grand Prime, On7 88 | - Sony Xperia E5, X, Z5 [Compact/Premium], C5 Ultra, C3, M4 Aqua [Dual] 89 | - Xiaomi Redmi 3, Note 2, Note 3, Mi 4, Mi 4i, Mi 5, Mi Max 90 | - ZTE Maven, ZMAX 2, Zmax Pro, Warp Elite 91 | - Android TVs 92 | - Sony Bravia 2015 93 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.3.1' 8 | } 9 | } 10 | 11 | apply plugin: 'com.android.library' 12 | 13 | android { 14 | compileSdkVersion 23 15 | buildToolsVersion "23.0.2" 16 | 17 | defaultConfig { 18 | minSdkVersion 16 19 | targetSdkVersion 23 20 | versionCode 1 21 | versionName "1.0" 22 | } 23 | lintOptions { 24 | abortOnError false 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | compile 'com.facebook.react:react-native:+' 31 | compile 'org.altbeacon:android-beacon-library:2+' 32 | } 33 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /android/src/main/java/com/ibeacon/simulator/BeaconBroadcast.java: -------------------------------------------------------------------------------- 1 | 2 | package com.ibeacon.simulator; 3 | 4 | import android.bluetooth.le.AdvertiseCallback; 5 | import android.bluetooth.le.AdvertiseSettings; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.ServiceConnection; 9 | import android.os.RemoteException; 10 | import android.support.annotation.Nullable; 11 | import android.util.Log; 12 | 13 | import com.facebook.react.bridge.ReactApplicationContext; 14 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 15 | import com.facebook.react.bridge.ReactMethod; 16 | import com.facebook.react.bridge.Callback; 17 | import com.facebook.react.bridge.Arguments; 18 | import com.facebook.react.bridge.ReactContext; 19 | import com.facebook.react.bridge.ReactMethod; 20 | import com.facebook.react.bridge.ReadableArray; 21 | import com.facebook.react.bridge.ReadableMap; 22 | import com.facebook.react.bridge.WritableArray; 23 | import com.facebook.react.bridge.WritableMap; 24 | import com.facebook.react.bridge.WritableNativeArray; 25 | import com.facebook.react.bridge.WritableNativeMap; 26 | import com.facebook.react.modules.core.DeviceEventManagerModule; 27 | 28 | import org.altbeacon.beacon.Beacon; 29 | import org.altbeacon.beacon.BeaconConsumer; 30 | import org.altbeacon.beacon.BeaconManager; 31 | import org.altbeacon.beacon.BeaconParser; 32 | import org.altbeacon.beacon.BeaconTransmitter; 33 | import org.altbeacon.beacon.RangeNotifier; 34 | import org.altbeacon.beacon.Region; 35 | import org.altbeacon.beacon.startup.BootstrapNotifier; 36 | 37 | import java.io.Console; 38 | import java.util.ArrayList; 39 | import java.util.Arrays; 40 | import java.util.Collection; 41 | import java.util.HashMap; 42 | import java.util.List; 43 | import java.util.Map; 44 | import java.util.logging.Logger; 45 | 46 | 47 | public class BeaconBroadcast extends ReactContextBaseJavaModule { 48 | private static final String TAG = "BeaconBroadcast"; 49 | private final ReactApplicationContext context; 50 | private static android.content.Context applicationContext; 51 | private static final String SUPPORTED = "SUPPORTED"; 52 | private static final String NOT_SUPPORTED_MIN_SDK = "NOT_SUPPORTED_MIN_SDK"; 53 | private static final String NOT_SUPPORTED_BLE = "NOT_SUPPORTED_BLE"; 54 | private static final String NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS = "NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS"; 55 | private static final String NOT_SUPPORTED_CANNOT_GET_ADVERTISER = "NOT_SUPPORTED_CANNOT_GET_ADVERTISER"; 56 | private static BeaconTransmitter beaconTransmitter = null; 57 | 58 | public BeaconBroadcast(ReactApplicationContext reactContext) { 59 | super(reactContext); 60 | this.context = reactContext; 61 | } 62 | 63 | @Override 64 | public Map getConstants() { 65 | final Map constants = new HashMap<>(); 66 | constants.put(SUPPORTED, BeaconTransmitter.SUPPORTED); 67 | constants.put(NOT_SUPPORTED_MIN_SDK, BeaconTransmitter.NOT_SUPPORTED_MIN_SDK); 68 | constants.put(NOT_SUPPORTED_BLE, BeaconTransmitter.NOT_SUPPORTED_BLE); 69 | constants.put(NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS, BeaconTransmitter.NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS); 70 | constants.put(NOT_SUPPORTED_CANNOT_GET_ADVERTISER, BeaconTransmitter.NOT_SUPPORTED_CANNOT_GET_ADVERTISER); 71 | return constants; 72 | } 73 | 74 | @Override 75 | public String getName() { 76 | return TAG; 77 | } 78 | 79 | @ReactMethod 80 | public void checkTransmissionSupported(Callback cb) { 81 | int result = BeaconTransmitter.checkTransmissionSupported(context); 82 | cb.invoke(result); 83 | } 84 | 85 | @ReactMethod 86 | public void startSharedAdvertisingBeaconWithString(String uuid, int major, int minor,String identifier) { 87 | int manufacturer = 0x4C; 88 | Beacon beacon = new Beacon.Builder() 89 | .setId1(uuid) 90 | .setId2(String.valueOf(major)) 91 | .setId3(String.valueOf(minor)) 92 | .setManufacturer(manufacturer) 93 | .setBluetoothName(identifier) 94 | .setTxPower(-59) 95 | .build(); 96 | BeaconParser beaconParser = new BeaconParser() 97 | .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"); 98 | this.beaconTransmitter = new BeaconTransmitter(context, beaconParser); 99 | this.beaconTransmitter.startAdvertising(beacon, new AdvertiseCallback() { 100 | 101 | @Override 102 | public void onStartFailure(int errorCode) { 103 | Log.d("ReactNative", "Error from start advertising " + errorCode); 104 | } 105 | 106 | @Override 107 | public void onStartSuccess(AdvertiseSettings settingsInEffect) { 108 | Log.d("ReactNative", "Success start advertising"); 109 | } 110 | }); 111 | } 112 | 113 | @ReactMethod 114 | public void stopSharedAdvertisingBeacon() { 115 | if(this.beaconTransmitter != null) { 116 | try { 117 | this.beaconTransmitter.stopAdvertising(); 118 | } catch (Exception ex) { 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /android/src/main/java/com/ibeacon/simulator/BeaconBroadcastPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.ibeacon.simulator; 3 | 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | import com.facebook.react.bridge.JavaScriptModule; 13 | 14 | public class BeaconBroadcastPackage implements ReactPackage { 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Arrays.asList(new BeaconBroadcast(reactContext)); 17 | } 18 | 19 | public List> createJSModules() { 20 | return Collections.emptyList(); 21 | } 22 | 23 | public List createViewManagers(ReactApplicationContext reactContext) { 24 | return Collections.emptyList(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule BeaconBroadcast 3 | * @flow 4 | */ 5 | 'use strict'; 6 | import React from 'react'; 7 | import { 8 | NativeModules, 9 | } from 'react-native'; 10 | 11 | const NativeBeaconBroadcast = NativeModules.BeaconBroadcast; 12 | 13 | const BeaconBroadcast = { 14 | checkTransmissionSupported: function() { 15 | return new Promise((resolve, reject) => { 16 | NativeBeaconBroadcast.checkTransmissionSupported(function(result) { 17 | const errors = { 18 | 1: 'NOT_SUPPORTED_MIN_SDK', 19 | 2: 'NOT_SUPPORTED_BLE', 20 | 3: 'DEPRECATED_NOT_SUPPORTED_MULTIPLE_ADVERTISEMENTS', 21 | 4: 'NOT_SUPPORTED_CANNOT_GET_ADVERTISER', 22 | 5: 'NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS' 23 | } 24 | if (result === 0) { 25 | resolve() 26 | } else { 27 | reject(errors[result]) 28 | } 29 | }); 30 | }); 31 | }, 32 | startAdvertisingBeaconWithString: function (uuid, identifier, major, minor) { 33 | NativeBeaconBroadcast.startSharedAdvertisingBeaconWithString(uuid, major, minor, identifier); 34 | }, 35 | 36 | stopAdvertisingBeacon: function () { 37 | NativeBeaconBroadcast.stopSharedAdvertisingBeacon(); 38 | }, 39 | }; 40 | 41 | export default BeaconBroadcast; 42 | -------------------------------------------------------------------------------- /index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule BeaconBroadcast 3 | * @flow 4 | */ 5 | 'use strict'; 6 | import React from 'react'; 7 | import { 8 | NativeModules, 9 | } from 'react-native'; 10 | 11 | const NativeBeaconBroadcast = NativeModules.BeaconBroadcast; 12 | 13 | /** 14 | * High-level docs for the BeaconBroadcast iOS API can be written here. 15 | */ 16 | 17 | const BeaconBroadcast = { 18 | startAdvertisingBeaconWithString: function (uuid, identifier, major, minor) { 19 | NativeBeaconBroadcast.startSharedAdvertisingBeaconWithString(uuid, major, minor, identifier); 20 | }, 21 | 22 | stopAdvertisingBeacon: function () { 23 | NativeBeaconBroadcast.stopSharedAdvertisingBeacon(); 24 | }, 25 | }; 26 | 27 | export default BeaconBroadcast; 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-ibeacon-simulator", 3 | "version": "1.0.10", 4 | "description": "A cool package for simulate your iOS devices as beacon", 5 | "author": "Flow", 6 | "nativePackage": true, 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/williamtran29/react-native-ibeacon-simulator.git" 10 | }, 11 | "keywords": [ 12 | "react-native", 13 | "react", 14 | "bluetooth", 15 | "ibeacon", 16 | "beacon simulator" 17 | ], 18 | "license": "MIT" 19 | } 20 | --------------------------------------------------------------------------------