光明程辉

光明程辉 查看完整档案

广州编辑  |  填写毕业院校  |  填写所在公司/组织填写个人主网站
编辑

IOS开发者

个人动态

光明程辉 关注了专栏 · 2018-10-20

随笔

随笔--技术总结日志

关注 74

光明程辉 关注了专栏 · 2018-09-14

冴羽的JavaScript博客

冴羽写JS文章的地方,预计写四个系列:JavaScript深入系列、JavaScript专题系列 、ES6系列、React系列。

关注 1464

光明程辉 关注了问题 · 2016-12-06

解决武汉大学720度全景漫游系统3D地图的实现思路是怎么样的?

关注 8 回答 1

光明程辉 关注了问题 · 2016-09-23

解决适配ios9出现的问题:-canOpenURL: failed for URL

-canOpenURL: failed for URL: "wtloginmqq2://qzapp" - error: "(null)"
2015-09-13 15:51:10.903[2948:1118021] -canOpenURL: failed for URL: "mqqopensdkapiV3://qzapp" - error: "(null)"
2015-09-13 15:51:10.904[2948:1118021] -canOpenURL: failed for URL: "mqqwpa://qzapp" - error: "(null)"
2015-09-13 15:51:10.905[2948:1118021] -canOpenURL: failed for URL: "mqqopensdkapiV2://qzapp" - error: "This app is not allowed to query for scheme mqqopensdkapiV2"
2015-09-13 15:51:10.906[2948:1118021] -canOpenURL: failed for URL: "mqqOpensdkSSoLogin://qqapp" - error: "This app is not allowed to query for scheme mqqOpensdkSSoLogin"
2015-09-13 15:51:10.906[2948:1118021] -canOpenURL: failed for URL: "mqq://qqapp" - error: "This app is not allowed to query for scheme mqq"
2015-09-13 15:51:10.907[2948:1118021] -canOpenURL: failed for URL: "mqzoneopensdkapiV2://qzapp" - error: "This app is not allowed to query for scheme mqzoneopensdkapiV2"
2015-09-13 15:51:10.908[2948:1118021] -canOpenURL: failed for URL: "mqzoneopensdkapi19://qzapp" - error: "This app is not allowed to query for scheme mqzoneopensdkapi19"
2015-09-13 15:51:10.909[2948:1118021] -canOpenURL: failed for URL: "mqzoneopensdkapi://qzapp" - error: "This app is not allowed to query for scheme mqzoneopensdkapi"
2015-09-13 15:51:10.910[2948:1118021] -canOpenURL: failed for URL: "mqzoneopensdk://qzapp" - error: "This app is not allowed to query for scheme mqzoneopensdk"
2015-09-13 15:51:10.911[2948:1118021] -canOpenURL: failed for URL: "mqzone://qzapp" - error: "This app is not allowed to query for scheme mqzone"
2015-09-13 15:51:10.911[2948:1118021] -canOpenURL: failed for URL: "wtloginmqq2://qzapp" - error: "(null)"
2015-09-13 15:51:10.912[2948:1118021] -canOpenURL: failed for URL: "mqqopensdkapiV3://qzapp" - error: "(null)"

现在app在ios9运行出现了这些,查了下资料。
根据网上的做法。

iOS9 URL Schemes 

除了要在项目info URL Types中设置URL Schemes,还需要在info.plist里面增加可信任的调用app,否则回报如下错误

-canOpenURL: failed for URL: "weixin://app/wx9c8771d3c07dfd30/" - error: "This app is not allowed to query for scheme weixin"

-canOpenURL: failed for URL: "wtloginmqq2://qzapp" - error: "This app is not allowed to query for scheme wtloginmqq2"

info.plist加入

<key>LSApplicationQueriesSchemes</key>

<array>

<string>urlscheme</string>

<string>urlscheme2</string>

<string>urlscheme3</string>

<string>urlscheme4</string>

</array>

我加入之后。

本来加入之前提示:
-canOpenURL: failed for URL: "mqqopensdkapiV2://qzapp" - error: "This app is not allowed to query for scheme mqqopensdkapiV2"

加入之后,error原因就没有了。如下:

-canOpenURL: failed for URL: "mqqopensdkapiV2://qzapp" - error: "(null)"

可是仍然是fail的。不知道如何解决?

关注 19 回答 13

光明程辉 回答了问题 · 2016-09-23

解决适配ios9出现的问题:-canOpenURL: failed for URL

这个解决2个问题就可以了:1首先在info.plist文件里添加

<key>LSApplicationQueriesSchemes</key>

<array>
    <string>hui123BBB</string>
    <!--        <string>urlscheme2</string>-->
    <!--        <string>urlscheme3</string>-->
    <!--        <string>urlscheme4</string>-->
</array>

2、然后,urlscheme 填对就可以了:
UIApplication *app = [UIApplication sharedApplication];

NSURL *url = [NSURL URLWithString:@"hui123BBB://"];

[[UIApplication sharedApplication] openURL:url];

if ([app canOpenURL:url]) {

    [app openURL:url];
    
}else{
    NSLog(@"打开错误");
}

关注 19 回答 13

光明程辉 关注了问题 · 2015-09-18

IOS蓝牙4.0 发送命令,没有接收到返回

IOS蓝牙4.0 发送命令,没有接收到返回。

首先是命令,是肯定有返回的。 没有返回是不是命令数据过大 ?如果是数据过大,有解决的办法吗? 请高手指教下

以下数据
{55,0,95,cc,0,91,a0,c2,0,0,8c,d1,81,89,2,2,83,81,b,81,82,60,5,a1,10,28,f1,7f,f6,60,80,12,11,52,14,23,72,7,0,3,21,1,1,70,0,0,68,11,6,0,5,5,b0,0,f2,63,83,a5,8a,37,d6,98,10,ee,eb,6,66,29,69,a6,9b,12,1f,a8,be,7a,9a,bb,c6,bb,b3,d9,99,7f,7f,eb,a5,bf,52,df,7b,c,30,23,f,63,42,3d,83,2a,e2,3a,bb,7c,67,78,4,48,2d,d8,1e,9d,be,b9,79,fa,db,c3,f9,df,2c,a0,e2,5e,11,5b,76,bb,7e,8f,9,9b,e0,c4,fd,f1,e9,3c,6c,eb,39,b6,d3,73,81,a1,22,36,fe,e0,cb,7d}

关注 1 回答 0

光明程辉 关注了问题 · 2015-09-18

iOS蓝牙开发,数据发送遇到问题

小弟目前在做iOS的蓝牙开发,用CoreBluetooth框架,目前从非iOS外设处接收数据已经没有问题了,但是发送数据一直不成功,外设收不到数据,用lightblue却可以正常收发数据,想问问大家是什么原因。

谢谢!

蓝牙模块的代码如下

#define kServiceUUID @"FFE0"
#define kCharacteristicUUID @"FFE1"
#import "BTManager.h"
@interface BTManager()
@property (strong,nonatomic) NSMutableArray *peripherals;   //连接的外围设备
@property (nonatomic, strong) CBCharacteristic *writeCharacteristic;
@end
@implementation BTManager

#pragma mark - Public Methods
- (void)writeToPeripheral:(NSString *)dataString {
    NSLog(@"writeToPeripheral:%@",dataString);
    if(_writeCharacteristic == nil){
        NSLog(@"writeCharacteristic 为空");
        return;
    }
    NSData *value = [self dataWithHexstring:dataString];
    NSLog(@"十六进制:%@",value);
    [_peripheral writeValue:value forCharacteristic:_writeCharacteristic type:CBCharacteristicWriteWithResponse];
    NSLog(@"已经向外设%@的特征值%@写入数据",_peripheral.name,_writeCharacteristic.description);
}

- (void)scan{                         options:@{CBCentralManagerScanOptionAllowDuplicatesKey:@YES}];
    [manager scanForPeripheralsWithServices:nil
                                    options:nil];
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
        manager.delegate = self;
    }
    return self;
}
#pragma mark - CBCentralManager Delegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSString * state = nil;

    switch ([central state])
    {
        case CBCentralManagerStateUnsupported:
            state = @"StateUnsupported";
            break;
        case CBCentralManagerStateUnauthorized:
            state = @"StateUnauthorized";
            break;
        case CBCentralManagerStatePoweredOff:
            state = @"PoweredOff";
            break;
        case CBCentralManagerStatePoweredOn:
            state = @"PoweredOn";
            break;
        case CBCentralManagerStateUnknown:
            state = @"unknown";
            break;
        default:
            break;
    }
    NSLog(@"手机状态:%@", state);
}
// 发现外设后
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
     advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSString *str = [NSString stringWithFormat:@"发现外设:%@ rssi:%@, UUID:%@ advertisementData: %@ ", peripheral, RSSI, peripheral.identifier.UUIDString, advertisementData];
    NSLog(@"%@",str);
    [_peripherals addObject:peripheral];

    if ([peripheral.name isEqualToString:@"BT"]) {
        [manager stopScan];
        [manager connectPeripheral:peripheral options:nil];
        NSLog(@"连接外设:%@",peripheral.description);
        self.peripheral = peripheral;
    }
}
// 连接到外设后
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
    NSLog(@"已经连接到:%@", peripheral.description);
    peripheral.delegate = self;
    [central stopScan];
    [peripheral discoverServices:nil];
}
// 连接失败后
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {

}
// 断开外设
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
}
#pragma mark - CBPeripheral Delegate
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    NSLog(@"didDiscoverServices");
    if (error) {
        NSLog(@"搜索服务%@时发生错误:%@", peripheral.name, [error localizedDescription]);
        return;
    }
    for (CBService *service in peripheral.services) {
        //发现服务
        if ([service.UUID isEqual:[CBUUID UUIDWithString:kServiceUUID]]) {
            NSLog(@"发现服务:%@", service.UUID);
            [peripheral discoverCharacteristics:nil forService:service];
            break;
        }
    }
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
    if (error) {
        NSLog(@"搜索特征%@时发生错误:%@", service.UUID, [error localizedDescription]);
        return;
    }
    NSLog(@"服务:%@",service.UUID);
    for (CBCharacteristic *characteristic in service.characteristics) {
        NSLog(@"特征:%@",characteristic);
        //发现特征
        if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:kCharacteristicUUID]]) {
            NSLog(@"监听特征:%@",characteristic);//监听特征
            _writeCharacteristic = characteristic;
            [self.peripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
    }
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
    if (error)
    {
        NSLog(@"更新特征值%@时发生错误:%@", characteristic.UUID, [error localizedDescription]);
        return;
    }
    // 收到数据
    NSLog(@"%@",[self hexadecimalString:characteristic.value]);
}
#pragma mark - NSData and NSString

//将传入的NSData类型转换成NSString并返回
- (NSString*)hexadecimalString:(NSData *)data{
    NSString* result;
    const unsigned char* dataBuffer = (const unsigned char*)[data bytes];
    if(!dataBuffer){
        return nil;
    }
    NSUInteger dataLength = [data length];
    NSMutableString* hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
    for(int i = 0; i < dataLength; i++){
        [hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
    }
    result = [NSString stringWithString:hexString];
    return result;
}
//将传入的NSString类型转换成NSData并返回
- (NSData*)dataWithHexstring:(NSString *)hexstring{
    NSData* aData;
    return aData = [hexstring dataUsingEncoding: NSASCIIStringEncoding];
}
@end

关注 11 回答 8

认证与成就

  • 获得 0 次点赞
  • 获得 2 枚徽章 获得 0 枚金徽章, 获得 0 枚银徽章, 获得 2 枚铜徽章

擅长技能
编辑

开源项目 & 著作
编辑

(゚∀゚ )
暂时没有

注册于 2015-09-17
个人主页被 255 人浏览