這邊只是展示一下公司(小弟目前在beacon公司)常用到的:
先設定一個NSRegularExpression物件
@property (strong, nonatomic) NSRegularExpression *uuidRegex;
之後可以在viewDidLoad設定這個物件的正則表達式
NSString *uuidPatternString = @"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
self.uuidRegex = [NSRegularExpression regularExpressionWithPattern:uuidPatternString
options:NSRegularExpressionCaseInsensitive
error:nil];
之後可以在user輸入的地方,檢查這個物件
- (void)uuidTextFieldChanged:(UITextField *)textField {
NSInteger numberOfMatches = [self.uuidRegex numberOfMatchesInString:textField.text
options:kNilOptions
range:NSMakeRange(0, textField.text.length)];
if (numberOfMatches > 0) {
self.UUIDFieldValid = YES;
} else {
self.UUIDFieldValid = NO;
}
self.saveBarButtonItem.enabled = self.isNameFieldValid && self.isUUIDFieldValid;
}
附上網址:
https://www.raywenderlich.com/66584/ios7-ibeacons-tutorial
附上網址:
https://www.raywenderlich.com/66584/ios7-ibeacons-tutorial
沒有留言:
張貼留言