I need to edit the advertisement data of bluetooth peripheral from central manager.
i tried a lot..
The following code provides the details :
1.After the Peripheral connection:
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
NSLog(#"Connection successfull to peripheral: %#",peripheral);
peripheral.delegate = self;
[peripheral discoverServices:nil];
//Do somenthing after successfull connection.
}
2.Discovering Services:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
for (CBService *service in peripheral.services) {
NSLog(#"Discovering characteristics for service %#", service);
[peripheral discoverCharacteristics:nil forService:service];
}
}
3.Discovering characteristics from service:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:#"B0702880-A295-A8AB-F734-031A98A512DE"]]) {
[peripheral readValueForCharacteristic:characteristic];
NSLog(#"Reading value for characteristic %#", characteristic);
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}
}
4.Updating Notification State:
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
NSLog(#"characteristic.properties--------------------->%lu",(unsigned long)characteristic.properties);
if (error) {
NSLog(#"Error changing notification state: %#",[error localizedDescription]);
}
// Notification has started
if (characteristic.isNotifying) {
NSLog(#"Notification began on %#", characteristic);
}
NSString* decodeString = #"teststring";
NSData *encodeData = [decodeString dataUsingEncoding:NSUTF8StringEncoding];
NSLog(#"to write----- %#",encodeData);
if ((characteristic.properties & CBCharacteristicPropertyWrite) ||
(characteristic.properties & CBCharacteristicPropertyWriteWithoutResponse))
{
[peripheral writeValue:encodeData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
else
{
NSLog(#"Not permit to write");
}
}
5.Update Write value in Peripheral:
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if (error) {
NSLog(#"Error writing characteristic value: %#",[error localizedDescription]);
}
NSData *data = characteristic.value;
NSLog(#"FinalData:%#",data);
}
i am new to IOS.Helps are appreciated
thanks in advance..
There is no general way of setting advertising data on the peripheral from the central. If you want to do something like this you either have to implement the feature on the peripheral (through a purpose made GATT Service), or this feature is offered by the product somehow.
Also note that advertising is a link layer (LL) feature, and those are normally not exposed by iOS. The iOS APIs for BLE is GAP/GATT level.
Related
I am trying to read all the services available and their characteristics value using CoreBluetooth framework from a device.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(#"Received peripheral : \n%#", peripheral);
NSLog(#"Adv data : %#", advertisementData);
self.activeperipheral=peripheral;
[self.myCentralManager connectPeripheral:peripheral options:nil];
if(peripheral.state==CBPeripheralStateConnected){
peripheral.delegate=self;
NSLog(#"Connected");
}
else
NSLog(#"Not Connected");
NSArray *serviceUUIDs=[advertisementData objectForKey:CBAdvertisementDataServiceUUIDsKey];
for(CBUUID *foundserviceUUIDs in serviceUUIDs){
if([serviceUUIDs containsObject:foundserviceUUIDs]){
NSLog(#"%#",serviceUUIDs);
}
}
}
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
for(CBService *service in peripheral.services){
[peripheral discoverCharacteristics:nil forService:service];
NSLog(#"Discover Service:%#",service);
}
}
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
for(CBCharacteristic *characteristic in service.characteristics){
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
self.myCharacteristic=characteristic;
NSLog(#"NotifyValue set on %#",characteristic);
//[peripheral readValueForCharacteristic:myCharacteristic];
}
}
-(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
if(characteristic.isNotifying)
NSLog(#"Notification began on %#",characteristic);
}
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
NSLog(#"%#",characteristic);
// NSLog(#"Characteristic Value Updated");
}
- (int)scanForPeripherals {
NSLog(#"Scanning");
if(self.myCentralManager.state!=CBCentralManagerStatePoweredOn)
NSLog(#"Turn on Bluetooth");
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey,
nil];
NSLog(#"Scanning");
[myCentralManager scanForPeripheralsWithServices:nil options:options];
return 0;
}
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
NSLog(#"Peripheral Connected");
peripheral.delegate=self;
//CBUUID *serviceUUID=[CBUUID UUIDWithString:#"1804"];
[peripheral discoverServices:nil];
//[myCentralManager stopScan];
}
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
NSLog(#"didDisconnectPeripheral");
}
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
NSLog(#"failed to connect");
}
- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error {
NSLog(#"didReadRSSI");
}
#end
The problem is I cannot setNotifyValue : Yes for other characteristics except the BatteryLevel characteristic and I am also getting the notification for the same only.
Here is my output.
Any idea what am I doing wrong here?
Thanks
That because your characteristic settings in gatt file (your bluetooth project) is not properly setup. See for example another characteristic settings and update your gatt file.
Another way to get characteristic value use a timer in which read your charackteristic:
-(void)TimerFunction
{
[talking_peripher readValueForCharacteristic:_talk_charack];
NSlog("VALUE: %#" _talk_charack);
}
And that is all. But actually best to do - modify your characteristic settings in gatt file (bluetooth project).
I have a connected & paired up Bluetooth LE bracelet (Service ID: FF20), which have 2 characteristics:
0xFF21 : Write without Response
0xFF22 : Notify
Now I try to write data via CoreBluetooth Framework to 0xFF21 with the following code:
I defined 2 constants at header file:
#define TRANSFER_SERVICE_UUID #"FF20"
#define TRANSFER_SERVICE_CHARACTERISTIC_UUID #"FF21"
.m
- (void)viewDidLoad {
[super viewDidLoad];
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
if (central.state != CBCentralManagerStatePoweredOn) {
return;
}
if (central.state == CBCentralManagerStatePoweredOn) {
NSArray* connectedDevices = [_centralManager retrieveConnectedPeripheralsWithServices:#[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]];
for (CBPeripheral *peripheral in connectedDevices) {
NSLog(#"Device Found. CBPeripheral = %#", peripheral);
peripheral.delegate = self;
if(peripheral.services.count == 0) {
NSLog(#"No service found");
}
for (CBService *service in peripheral.services) {
if(service.characteristics != nil) {
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
// check notifying ?
NSData *data = [#"Testing" dataUsingEncoding:NSUTF8StringEncoding];
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
} else {
NSLog(#"Specific Characteristic Not found");
}
}
} else {
NSLog(#"Characteristic is NULL");
}
}
}
}
}
The log appears:
Device Found. CBPeripheral = <CBPeripheral: 0x1740f5080, identifier = 4EFF694C-017A-536F-9301-2EB2CC316CBE, name = Bracelet-0366, state = disconnected>
No service found
What did I miss?
You need to issue a connect to the discovered peripheral and get a call to your didConnectPeripheral delegate method before you can issue read/write requests.
When you reach the poweredOn state you should issue a scanForDevicesWithServices call, wait for the call back to your delegate, then connect, discover the service and characteristics, then you can issue a write.
-(void) centralManagerDidUpdateState:(CBCentralManager *)central {
switch (central.state) {
case CBCentralManagerStatePoweredOn:
[central scanForPeripheralsWithServices:#[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] options:nil];
break;
}
}
-(void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(#"Discovered peripheral %# (%#)",peripheral.name,peripheral.identifier.UUIDString);
if (self.connectedPeripheral == nil) {
[central connectPeripheral:peripheral options:nil];
}
}
-(void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
self.connectedPeripheral=peripheral;
NSLog(#"Connected to %#(%#)",peripheral.name,peripheral.identifier.UUIDString);
peripheral.delegate=self;
[peripheral discoverServices:#[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]];
}
-(void) peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
for (CBService *service in peripheral.services) {
NSLog(#"Discovered service %#",service.description);
[peripheral discoverCharacteristics:nil forService:service];
}
}
-(void) peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
for (CBCharacteristic *characteristic in service.characteristics ) {
NSLog(#"Discovered characteristic %#(%#)",characteristic.description,characteristic.UUID.UUIDString);
if ([characteristic.UUID.UUIDString isEqualToString:TRANSFER_SERVICE_CHARACTERISTIC_UUID) {
NSData *data = [#"Testing" dataUsingEncoding:NSUTF8StringEncoding];
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];
}
}
}
Note, that from your previous question the characteristic only supports write without response, so you can't use CBCharacteristicWriteWithResponse
I want to use BLE device for IOS which has on/off lights & coloured lights. I am connecting bluetooth using core bluetooth framework.
Now i want on/off or change colour of lights. How to do this from central as app to peripheral as bluetooth device, what are all methods required to do this function ?
1) Scan with nil service id (if you are using in background you would need service id)
2) Scan
[self.centralManager scanForPeripheralsWithServices:nil
options:nil];
3) You would get devices in this delegate method
- (void) centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI {
// check advertisementData for service UUID
[self.centralManager connectPeripheral:peripheral options:nil];
}
4) on successful Connection
- (void) centralManager:(CBCentralManager *)central
didConnectPeripheral:(CBPeripheral *)peripheral {
[peripheral discoverServices:nil];
}
5) on services discoverd
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
if (error) {
NSLog(#"Error discovering services: %#", [error localizedDescription]);
return;
}
// Discover the characteristic we want...
// Loop through the newly filled peripheral.services array, just in case there's more than one.
for (CBService *service in peripheral.services) {
[peripheral discoverCharacteristics:nil forService:service];
}
}
6) on retrieving charactesicts
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
// Deal with errors (if any)
if (error) {
NSLog(#"Error discovering characteristics: %#", [error localizedDescription]);
return;
}
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {
// And check if it's the right one
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:#"FFF1"]]) {
scannedcharacteristic = characteristic;
NSString *str = writeValue.length == 0 ? #"z" : writeValue;
DDLogVerbose(#"Writing value %#", str);
NSData *expectedData = [str dataUsingEncoding:NSUTF8StringEncoding];
[peripheral writeValue:expectedData forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
// [peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}
In my CBPeripheralDelegate I have the following methods
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
if (error) {
DDLogError(#"Error discovering services: %#", [error localizedDescription]);
return;
}
// Loop through the newly filled peripheral.services array, just in case there's more than one.
for (CBService *service in peripheral.services) {
NSArray *uids = #[[CBUUID UUIDWithString:kSendDataCharacteristicUUID],
[CBUUID UUIDWithString:kReceiveDataCharacteristicUUID]];
[peripheral discoverCharacteristics:uids
forService:service];
}
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
// Deal with errors (if any)
if (error) {
DDLogError(#"Error discovering characteristics: %#", [error localizedDescription]);
return;
}
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:kReceiveDataCharacteristicUUID]]) {
_receiveCharacteristic = characteristic;
[_peripheral setNotifyValue:YES
forCharacteristic:characteristic];
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:kSendDataCharacteristicUUID]]) {
_sendCharacteristic = characteristic;
}
}
if (_sendCharacteristic && _receiveCharacteristic) {
[self allServicesDiscovered];
}
}
However, since ios 8.3, the "kReceiveDataCharacteristicUUID" characteristic is no longer discovered.
I have verified this with and external BLE discovery app, and it gives the same.\
Is there some way to manually add a non discovered service?
Edit: here is the hardware debug log from our engineers. It looks like ios is starting 1 bit later than what it used to.
Android (Note ATT starts at 0x0003)
iOS 8.3 (Note ATT starts at 0x0004)
I am trying to develop iOS app, which is detecting BLE device and need to invoke a write command. I can successfully connect to BLE device and discover its service and characteristics. But I am getting an Unknown Error during the write data on connected peripheral. Below is the code what I have written:
Discovered Characteristic:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
NSArray *characteristics = [service characteristics];
if (peripheral != self.peripheral) {
NSLog(#"Wrong Peripheral.\n");
return ;
}
if (error != nil) {
NSLog(#"Error %#\n", error);
return ;
}
for (CBCharacteristic *characteristic in characteristics) {
if ([[characteristic UUID] isEqual:RWT_POSITION_CHAR_UUID]) {
self.positionCharacteristic = characteristic;
}
}
}
Here is the function for write data on BLE device
- (void)writeCommand{
// See if characteristic has been discovered before writing to it
if (!self.positionCharacteristic) {
return;
}
NSString *cmd1=#"CQ+WHORU\r";
NSData *dataToWrite = [cmd1 dataUsingEncoding:NSUTF8StringEncoding];
CBCharacteristic *chr = self.positionCharacteristic;
NSLog(#"%#,%lu...%#",chr.UUID,chr.properties,chr);
NSInteger dataSize = [[NSByteCountFormatter stringFromByteCount:dataToWrite.length countStyle:NSByteCountFormatterCountStyleFile] integerValue];
if (dataSize > 130) {
NSLog(#"Cannot send more than 130 bytes");
}
else
{
[self.peripheral writeValue:dataToWrite forCharacteristic:self.positionCharacteristic type:CBCharacteristicWriteWithResponse];
}
}
- (void)peripheral:(CBPeripheral *)peripheral
didWriteValueForCharacteristic:(CBCharacteristic *)characteristic
error:(NSError *)error
{
if (error)
{
NSLog(#"Error writing characteristic value: %#", [error localizedDescription]);
}
else
{
NSLog(#"Successfully writing characteristic value");
}
}
In "didWriteValueForCharacteristic" delegate method I am getting below error:
Error writing characteristic value: Unknown error.
What could be possibly be the reason for this error?
Also If I am trying to define characteristic for sending data on BLE device like:
CBMutableCharacteristic *writeChar = [[CBMutableCharacteristic alloc]initWithType:[CBUUID UUIDWithString:#"ffe1"] properties:CBCharacteristicPropertyWriteWithoutResponse|CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsWriteable|CBAttributePermissionsReadable];
int8_t cmd = *[cmd1 UTF8String];
NSData *data = [NSData dataWithBytes:&cmd length:sizeof(cmd)];
NSInteger dataSize = [[NSByteCountFormatter stringFromByteCount:dataToWrite.length countStyle:NSByteCountFormatterCountStyleFile] integerValue];
if (dataSize > 130) {
NSLog(#"Cannot send more than 130 bytes");
}
else
{
[self.peripheral writeValue:dataToWrite forCharacteristic:writeChar type:CBCharacteristicWriteWithResponse];
// [self.peripheral writeValue:dataToWrite forCharacteristic:writeChar type:CBCharacteristicWriteWithResponse];
}
then I am getting this error:
**CoreBluetooth[WARNING] CBMutableCharacteristic: 0x1552a270 UUID = Unknown (<ffe1>),Value = (null), Properties = 0x14, Permissions = 0x3, Descriptors = (null), SubscribedCentrals = (
)> is not a valid characteristic for peripheral <CBPeripheral: 0x15549930 identifier = FC71890D-9F71-5E16-086D-D491E1EF7599, Name = " DEMOBLE1", state = connected**
When you write the data you're requesting a response (CBCharacteristicWriteWithResponse).
The write will fail if the characteristic you're writing to does not have the property CBCharacteristicPropertyWrite set, but only supports writes without response (CBCharacteristicPropertyWriteWithoutResponse).
if ((self.positionCharacteristic.properties & CBCharacteristicPropertyWrite) == CBCharacteristicPropertyWrite) {
// Responses are available, so write with response.
[self.peripheral writeValue:dataToWrite forCharacteristic:self.positionCharacteristic type:CBCharacteristicWriteWithResponse];
}
else if ((self.positionCharacteristic.properties & CBCharacteristicPropertyWriteWithoutResponse) == CBCharacteristicPropertyWriteWithoutResponse) {
// Responses are not available.
// Write with response is going to fail, so write without response.
[self.peripheral writeValue:dataToWrite forCharacteristic:self.positionCharacteristic type:CBCharacteristicWriteWithoutResponse];
}
I have seen this error while developing both the iOS App (as Central) and the BLE Device firmware (as Peripheral). This would occur when I changed/modified the characteristics on the BLE peripheral.
iOS seems to cache information about the services and characteristics after a connection. I was able to solve this by updating the Bluetooth Address of the peripheral whenever I would build/download new firmware to the Device.
First of all, you are using CBCentralManager, right?
Make sure you are doing it in the right way:
Use CBCentralManager
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
Detect when a peripheral connected
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
if (connectedDevice) // make sure you disconnect previous device
[self.centralManager cancelPeripheralConnection:connectedDevice];
connectedDevice = [peripheral retain];
connectedDevice.delegate = self;
[connectedDevice discoverServices:nil]; // this will discover all kind of services
}
If something was wrong during the connection, you will find here (for example, low battery)
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
NSLog(#"Did fail to connect: %#",error.description);
connectedDevice = nil;
}
Something went wrong with a successfully connected BLE (for example, low battery, user turned off the device)
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
NSLog(#"Disconnected: %#",error.description);
connectedDevice = nil;
}
Here, you can find the available services
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog([NSString stringWithFormat:#"%#",[advertisementData description]]);
}
6.
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSString *messtoshow;
switch (central.state) {
case CBCentralManagerStatePoweredOn:
{
[NSString stringWithFormat:#"Bluetooth is currently powered on and available to use."];
CBUUID *heartRate = [CBUUID UUIDWithString:HRM_SERVICE_UUID];
CBUUID *batteryLevel = [CBUUID UUIDWithString:BATTERY_LIFE_SERVICE_UUID];
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[self.centralManager scanForPeripheralsWithServices:[NSArray arrayWithObjects:heartRate,batteryLevel,nil] options:scanOptions];
break;
}
}
}
From now on, you can implement the CBPeripheralDelegate methods
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
for (CBService *service in peripheral.services) {
NSLog(#"Discovered service: %#", service.UUID);
[peripheral discoverCharacteristics:nil forService:service];
}
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if ([service.UUID isEqual:[CBUUID UUIDWithString:HRM_SERVICE_UUID]]) {
for (CBCharacteristic *aChar in service.characteristics)
{
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:HRM_MEASUREMENT_CHARACTERISTIC_UUID]]) {
[connectedDevice setNotifyValue:YES forCharacteristic:aChar];
}
}
}
if ([service.UUID isEqual:[CBUUID UUIDWithString:BATTERY_LIFE_SERVICE_UUID]]) {
for (CBCharacteristic *aChar in service.characteristics)
{
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:BATTERY_LEVEL_CHARACTERISTIC_UUID]]) {
[connectedDevice readValueForCharacteristic:aChar];
}
}
}
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
NSError* err = nil;
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:HRM_MEASUREMENT_CHARACTERISTIC_UUID]]) {
NSData *data = [characteristic value];
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:BATTERY_LEVEL_CHARACTERISTIC_UUID]]) {
}
}
This should work fine. I've implemented it in the same way, and there isn't any problem. I hope this helps.