iOS跳转蓝牙

iOS跳转蓝牙设置

[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=****"]]

这个方法审核会被拒绝,那么怎样才能绕过苹果审核呢.
查了网上一些资料,把方法转换成ACSII值进行拼装,调用开启蓝牙的方法.

-(NSString *) getBluetoothMethod{
  NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
  NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
  NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
  NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
  NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];
  return method;
}

利用ASCII值进行拼装组合方法

-(NSString *) getDefaultWork{
  NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];
  NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];return method;
 }

开启蓝牙

-(void)setBlueTooth {
  NSString * defaultWork = [self getDefaultWork];
  NSString * bluetoothMethod = [self getBluetoothMethod];
  NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
  Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");  
  [[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];
}

你可能感兴趣的:(iOS跳转蓝牙)