如何播放Yosemite os作为灯塔?

时间:2015-12-28 05:42:23

标签: ios ibeacon

我试图将我的Yosemite OS广播作为灯塔,但我无法播放。我没有得到任何错误,但它不起作用。我已经提到了这个链接https://github.com/mgigirey/iBeaconSwiftOSX。 BLE也受支持。有没有办法让mac os成为灯塔?

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    self.manager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

    [self.uuidFieldCell setStringValue:@"B0702880-A295-A8AB-F734-031A98A512DE"];
    [self.majorFieldCell setStringValue:@"5"];
    [self.minorFieldCell setStringValue:@"1000"];
    [self.powerFieldCell setStringValue:@"-58"];

    self.isBroadcasting = NO;
    [self.statusField setStringValue:@"Not broadcasting"];



}

-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {

    if (peripheral.state == CBPeripheralManagerStatePoweredOn) {

        self.manager = peripheral;

//        NSUUID *proximityUUID = [[NSUUID alloc] initWithUUIDString:@"B0702880-A295-A8AB-F734-031A98A512DE"];
//        CMBeaconAdvertismentData *beaconData = [[CMBeaconAdvertismentData alloc] initWithProximityUUID:proximityUUID major:5 minor:5000 measuredPower:-58];
//        [peripheral startAdvertising:beaconData.beaconAdvertisement];

    }
}

-(IBAction)didTapToggleButton:(id)sender {

    if (self.manager && !self.isBroadcasting) {

        NSUUID *proxUUID = [[NSUUID alloc] initWithUUIDString:self.uuidFieldCell.stringValue];
        NSInteger major = [self.majorFieldCell.stringValue integerValue];
        NSInteger minor = [self.minorFieldCell.stringValue integerValue];
        NSInteger power = [self.powerFieldCell.stringValue integerValue];

        CMBeaconAdvertismentData *beaconData = [[CMBeaconAdvertismentData alloc] initWithProximityUUID:proxUUID
                                                                                                 major:major
                                                                                                 minor:minor
                                                                                         measuredPower:power];

        [self.manager startAdvertising:beaconData.beaconAdvertisement];
        self.isBroadcasting = YES;

        [self.statusField setStringValue:@"Broadcasting"];
        [self.toggleButton setTitle:@"Stop broadcasting"];

        [self.uuidFieldCell setEditable:NO];
        [self.uuidFieldCell setTextColor:[NSColor lightGrayColor]];
        [self.majorFieldCell setEditable:NO];
        [self.majorFieldCell setTextColor:[NSColor lightGrayColor]];
        [self.minorFieldCell setEditable:NO];
        [self.minorFieldCell setTextColor:[NSColor lightGrayColor]];
        [self.powerFieldCell setEditable:NO];
        [self.powerFieldCell setTextColor:[NSColor lightGrayColor]];

    } else if (self.manager && self.isBroadcasting) {

        [self.manager stopAdvertising];
        [self.statusField setStringValue:@"Not broadcasting"];

        self.isBroadcasting = NO;
        [self.toggleButton setTitle:@"Start broadcasting"];

        [self.uuidFieldCell setEditable:YES];
        [self.uuidFieldCell setTextColor:[NSColor blackColor]];
        [self.majorFieldCell setEditable:YES];
        [self.majorFieldCell setTextColor:[NSColor blackColor]];
        [self.minorFieldCell setEditable:YES];
        [self.minorFieldCell setTextColor:[NSColor blackColor]];
        [self.powerFieldCell setEditable:YES];
        [self.powerFieldCell setTextColor:[NSColor blackColor]];

    }

}

1 个答案:

答案 0 :(得分:0)

您使用的是外置蓝牙适配器吗?您需要一个能够在Yosemite上发布iBeacon数据包。

您提到的iBeaconSwiftOSX项目的自述文件:

  

注意:尽管很多论坛都说你不能使用Yosemite作为iBeacon,但我可以确认这个解决方案是有效的,但只能使用外部蓝牙适配器。 https://stackoverflow.com/a/27542365/3824765

上面注释中提到的其他Stack Overflow线程中的更多信息:
CBPeripheralManager startAdvertising not working on OS X yosemite