Ah finally i got the solution. Thanks for everyone who helped me. Here is the solution. Now i can call this write mtd anywhere & any number of times.
CBCharacteristic *Writechar = nil;
CBPeripheral *writePeri = nil;
-(void)peripheral:(CBPeripheral *)peripheral
didDiscoverCharacteristicsForService:(CBService *)service
error:(NSError *)error
{
for (CBCharacteristic *characteristic in service.characteristics)
{
[peripheral readValueForCharacteristic:characteristic];
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]])
{
Writechar = (CBCharacteristic*)characteristic.UUID;
writePeri = (CBPeripheral*)peripheral;
[writePeri readValueForCharacteristic:characteristic];
[writePeri setNotifyValue:YES forCharacteristic:characteristic];
}
}
}
- (void) write
{
for(CBService *service in writePeri.services)
{
for (CBCharacteristic *characteristic in service.characteristics) {
[writePeri readValueForCharacteristic:characteristic];
[writePeri setNotifyValue:YES forCharacteristic:characteristic];
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"ABCD"]])
{
[writePeri writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
}
}
}