0

When I use [CBUUID UUIDWithString:@"xxx"], something like that the invalid uuid string, the app will crash. How to check if the param is a valid UUID-format.

The error is:

Assertion failure in -[CBUUID initWithString:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/MobileBluetoothFramework/MobileBluetooth-115.5.1/CoreBluetooth/CoreBluetooth/CBUUID.m:149

I can't understand why the assertion happens on release version. Maybe Apple forget to turn off assertion switch.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
zedzhao
  • 517
  • 1
  • 3
  • 17
  • where are you getting the UUID from, the system or are you creating one? – Asleepace Mar 13 '19 at 02:47
  • The inputed UUID may from anywhere, but I need to make sure the app can't be crashed. So I have to make sure the input string is a valid format before I call UUIDWithString – zedzhao Mar 13 '19 at 03:02

1 Answers1

0

Try this:

-(BOOL)isUUID:(NSString *)string
{
   return !![[NSUUID alloc] initWithUUIDString:string]; 
}
Asleepace
  • 3,466
  • 2
  • 23
  • 36