0

広告とスキャンを同時に行うアプリケーションを作成しました。うまく機能していますが、問題があります。しばらくすると、mz 周辺機器の広告が停止します。

再起動しようとしましたが、電話とアプリケーションがまだ機能していません。

周辺機器の実装は次のとおりです。

@implementation PeripheralManager

+ (PeripheralManager*)sharedInstance
{
    static PeripheralManager *_sharedInstance = nil;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        _sharedInstance = [[PeripheralManager alloc] init];
    });
    return _sharedInstance;
}

-(id)initWithUUID:(NSString *)UUID{

    self = [super init];
    if(self) {
        self.UUID = UUID;
        self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

    }
    return self;
}
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
    if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
        return;
    }

    if (peripheral.state == CBPeripheralManagerStatePoweredOn) {



        self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID] properties:CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsWriteable];

        CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:self.UUID] primary:YES];

        transferService.characteristics = @[_transferCharacteristic];

        [_peripheralManager addService:transferService];


    }
}
-(void)startAdvertisment{
    [_peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:self.UUID]], CBAdvertisementDataLocalNameKey: PERIPHERAL_NAME}];


}
4

0 に答える 0