使用CoreBluetooth我想将数据从iPhone发送到Mac.为此,我编写了像iPhone一样的代码作为'Peripheral'和Mac作为'Central'.
它工作得很好,但有时会直接断开连接,然后连续连接和断开连接.
有时当它试图重新连接时,在中心它直接调用'didDisconnectPeripheral'委托方法.但有时它在'didUpdateNotificationStateForCharacteristic'中有错误"句柄无效".
我在网上提到了所有的链接.但我无法解决这个问题.我在iPhone中认为它存储了蓝牙缓存.
请提出解决方法如何解决"句柄无效"错误?
以下是一些重要的方法.
对于Peripheral,我写了如下代码.
在Appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.peripheral = [[PeripheralServerObject alloc] init];
self.peripheral.serviceUUID = [CBUUID UUIDWithString:@"4w24"];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在外围对象文件中:
//To Check Bluetooth State
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
switch (peripheral.state) {
case CBPeripheralManagerStatePoweredOn:
[self enableService];
break;
case CBPeripheralManagerStatePoweredOff: {
[self disableService];
break;
}
}
// To Add characteristics to Service
- (void)enableService
{
[self.peripheral removeAllServices];
self.service = [[CBMutableService alloc]
initWithType:self.serviceUUID primary:YES];
self.authChar =
[[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"a86e"]
properties:CBCharacteristicPropertyNotify
value:nil
permissions:CBAttributePermissionsReadable];
self.respChar =
[[CBMutableCharacteristic …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码来压缩视频.
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL
outputURL:(NSURL*)outputURL
handler:(void (^)(AVAssetExportSession*))handler
{
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
if (exportSession.status == AVAssetExportSessionStatusCompleted)
{
printf("completed\n");
NSLog(@"outputurl is %@",outputURL);
}
else
{
printf("error\n");
NSLog(@"error is %@",exportSession.error);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
在压缩后,视频在iOS6中的声音非常低,但在iOS 5中我获得了完整的原始音量,那么我如何在iOS 6中获得原始音量.
iphone objective-c mpmovieplayercontroller avfoundation ios6
我正在[info objectForKey:UIImagePickerControllerMediaURL]从UIImagepickercontroller的didFinishPickingMediaWithInfo方法获得输入.
NSURL *inputURL = [NSURL URLWithString:inputurlstring];
Run Code Online (Sandbox Code Playgroud)
我从这段代码中给出了outputurl
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *videoPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"capturedvideo.MOV"];
NSURL *outputURL = [NSURL fileURLWithPath:videoPath];
Run Code Online (Sandbox Code Playgroud)
我使用以下代码来获得低质量的视频
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL
outputURL:(NSURL*)outputURL
handler:(void (^)(AVAssetExportSession*))handler
{
[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
if (exportSession.status == AVAssetExportSessionStatusCompleted)
{
printf("completed\n");
}
else
{
printf("error\n");
NSLog(@"error is %@",exportSession.error);
}
}];
}
Run Code Online (Sandbox Code Playgroud)
我只使用大文件时出现以下错误.因为当我使用小尺寸视频文件时,我没有收到任何错误.
Error Domain=NSURLErrorDomain …Run Code Online (Sandbox Code Playgroud)