我有一个以前使用的iPhone应用程序,它使用蓝牙LE配件,我通过修改示例源代码创建。
在对Xcode和IOS进行的无数更新中,由于无法调试的原因,它已停止构建。
它与初始化CBService有关。
在线上构建崩溃,说'init'不可用:
CBService *gattDBService=[[CBService alloc] init];
反过来又指向CBAttribute.h中的这一行:
- (instancetype) init NS_UNAVAILABLE;
我现在正在使用XCode 7.0,项目设置为7.1的部署目标。
为什么这个项目开始这样做? 谢谢, 戴尔
进一步的代码片段(向carousel重新添加服务):
-(void)prepareCarouselList
{
NSArray *allService = [self UUIDArray:[[[CBManager sharedManager] serviceUUIDDict] allKeys]];
if (proximityServices)
{
[proximityServices removeAllObjects];
}
if (findMeServices)
{
[findMeServices removeAllObjects];
}
// Check for sensor hub
for (CBService *service in [[CBManager sharedManager] foundServices])
{
if ([service.UUID isEqual:BAROMETER_SERVICE_UUID])
{
[carouselArray addObject:[[[CBManager sharedManager] serviceUUIDDict] valueForKey:[service.UUID.UUIDString lowercaseString]]];
[carousel_ServiceArray addObject:service];
isSensorHubFound = YES;
break;
}
}
if (!isSensorHubFound)
{
for(CBService *service in [[CBManager sharedManager] foundServices])
{
if([allService containsObject:service.UUID])
{
NSInteger ServiceKeyIndex = [allService indexOfObject:service.UUID];
CBUUID *keyID = [allService objectAtIndex:ServiceKeyIndex];
if([service.UUID isEqual:CAPSENSE_SERVICE_UUID] || [service.UUID isEqual:CUSTOM_CAPSENSE_SERVICE_UUID])
{
[self checkCapsenseProfile:service];
}
else if(![self checkFindMeProfile:service])
{
if ([service.UUID isEqual:IMMEDIATE_ALERT_SERVICE_UUID])
{
[findMeServices addObject:service];
}
[carouselArray addObject:[[[CBManager sharedManager] serviceUUIDDict] valueForKey:[keyID.UUIDString lowercaseString]]];
[carousel_ServiceArray addObject:service];
}
}
else
{
NSDictionary *tempDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"unknown",k_SERVICE_IMAGE_NAME_KEY,[ResourceHandler getServiceNameForUUID:service.UUID],k_SERVICE_NAME_KEY, nil];
[[[CBManager sharedManager] serviceUUIDDict] setValue:tempDict forKey:[service.UUID.UUIDString lowercaseString]];
[carouselArray addObject:tempDict];
[carousel_ServiceArray addObject:service];
}
}
}
//To add GATT DB item
[self addGattDBCarouselItem];
if([carouselArray count])
{
[self initCarousel];
}
}
/*!
* @method addGattDBCarouselItem
*
* @discussion Method to add GATTDB carousel item
*
*/
-(void)addGattDBCarouselItem
{
[carouselArray insertObject:[[[CBManager sharedManager] serviceUUIDDict] valueForKey:GENERIC_ACCESS_SERVICE_UUID] atIndex:0];
CBService *gattDBService=[[CBService alloc] init];;
[carousel_ServiceArray insertObject:gattDBService atIndex:0];
}
答案 0 :(得分:2)
CBService没有init方法,但CBMutableService没有。试试这个:
-(void)addGattDBCarouselItem
{
[carouselArray insertObject:[[[CBManager sharedManager] serviceUUIDDict] valueForKey:GENERIC_ACCESS_SERVICE_UUID] atIndex:0];
NSString *keyAtIndex = [[[[CBManager sharedManager] serviceUUIDDict] allKeysForObject:carouselArray[0]] objectAtIndex:0];
CBUUID *keyID = [CBUUID UUIDWithString:keyAtIndex];
CBMutableService *gattDBService=[[CBMutableService alloc] initWithType:keyID primary:YES];
[carousel_ServiceArray insertObject:gattDBService atIndex:0];
}
答案 1 :(得分:1)
您无法创建CBService
的实例 - 在发现服务后,会从CBPeripheral
的{{1}}属性中检索此对象的实例。
如果您要将服务宣传为外围设备,则必须实例化services
实例。