我有一个以前可以使用的iPhone应用程序,该应用程序使用Bluetooth LE配件,并且是通过修改示例源代码创建的。

在无数Xcode和IOS更新中,由于我无法调试的原因,它已停止构建。

它与初始化CBService有关。

建筑物崩溃,并说“init”不可用:
CBService *gattDBService=[[CBService alloc] init];
依次指向CBAttribute.h中的这一行:
- (instancetype) init NS_UNAVAILABLE;
我现在正在使用XCode 7.0,并将该项目设置为7.1的部署目标。

为什么这个项目开始这样做?
谢谢,
戴尔

进一步的代码段(正在向轮播添加服务):

-(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];
}

最佳答案

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];
}

关于ios - 初始化CBService时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32773261/

10-10 21:01