小编W D*_*son的帖子

插入耳机或拔下耳机时,iOS应用程序崩溃

我在iOS 6.1.3 iPad2和新iPad上运行SIP音频流应用程序.

我在iPad上启动了我的应用程序(没有插入任何内容).
音频工作.
我插上耳机.
应用程序崩溃:malloc:对象0x的错误....:没有分配被释放的指针或EXC_BAD_ACCESS

或者:

我在iPad上启动了我的应用程序(耳机已插入).
音频来自耳机.
我拔下耳机.
应用程序崩溃:malloc:对象0x的错误....:没有分配被释放的指针或EXC_BAD_ACCESS

应用代码采用基于http://code.google.com/p/ios-coreaudio-example/示例代码的AudioUnit api (见下文).

我使用kAudioSessionProperty_AudioRouteChange回调来获得更改感知.因此,OS声音管理器有三个回调:
1)处理录制的麦克风样本
2)为扬声器提供样本
3)通知音频硬件存在

经过大量测试后,我的感觉是棘手的代码是执行麦克风捕获的代码.在插入/拔出动作之后,大多数时候在调用RouteChange之前调用记录回调几次导致以后的"分段错误"并且永远不会调用RouteChange回调.更具体地说,我认为AudioUnitRender函数会导致"内存不良访问",而根本不会抛出异常.

我的感觉是,非原子记录回调代码与OS声音设备相关结构的更新竞争.因此,非原子性的记录回调更可能是OS HW更新和记录回调的并发性.

我修改了我的代码以使录制回调尽可能地薄,但我的感觉是我的应用程序的其他线程带来的高处理负载正在为之前描述的并发竞争提供支持.因此,由于AudioUnitRender访问不良,代码的其他部分会出现malloc/free错误.

我试图通过以下方式减少录制回调延迟:

UInt32 numFrames = 256;
UInt32 dataSize = sizeof(numFrames);

AudioUnitSetProperty(audioUnit,
    kAudioUnitProperty_MaximumFramesPerSlice,
    kAudioUnitScope_Global,
    0,
    &numFrames,
    dataSize);
Run Code Online (Sandbox Code Playgroud)

我试图提出有问题的代码:

dispatch_async(dispatch_get_main_queue(), ^{
Run Code Online (Sandbox Code Playgroud)

有人有提示或解决方案吗?为了重现错误,这里是我的音频会话代码:

//
//  IosAudioController.m
//  Aruts
//
//  Created by Simon Epskamp on 10/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "IosAudioController.h"
#import <AudioToolbox/AudioToolbox.h>

#define kOutputBus 0
#define kInputBus 1

IosAudioController* …
Run Code Online (Sandbox Code Playgroud)

headphones audiounit ios

24
推荐指数
1
解决办法
2901
查看次数

是否有iCloud磁盘容量和使用的API?

我使用NSFileManager获取当前设备磁盘空间(总数,使用数和空闲数),如此...

let systemAttributes = try? NSFileManager.defaultManager().attributesOfFileSystemForPath(NSHomeDirectory() as String)
    let space = (systemAttributes?[NSFileSystemSize] as? NSNumber)?.longLongValue
Run Code Online (Sandbox Code Playgroud)

有没有办法为用户的iCloud帐户做类似的事情?我希望能够在应用程序中显示用户的iCloud磁盘空间统计信息.

xcode nsfilemanager icloud cloudkit ios9

14
推荐指数
1
解决办法
504
查看次数

UITextField在UITableViewCell帮助中

我已经浏览了互联网,寻找一个很好的教程或发布关于在每个单元格中填充UITextField以进行数据输入的UITableView.

我想跟踪每个UITextField以及滚动时写在其中的文本.tableView将被分区.我一直在使用自定义UITableViewCell,但我对任何方法都开放.

另外,是否可以将textFields用作ivars?

如果你们中的任何一个人能指出我正确的方向,我将不胜感激.

先感谢您!

iphone uitableview uitextfield ipad ios

11
推荐指数
2
解决办法
1万
查看次数

从UICollectionViewCell呈现UIPopoverController

我想从UICollectionViewCell上的按钮呈现UIPopoverController.

到目前为止,一切都已创建好,但弹出窗口不可见.

这有什么特别的方法吗?

如果我从集合视图单元格以外的任何其他位置显示代码,则代码可以工作.

以下代码位于UICollectionViewCell子类中.

if (_infoPopover == nil) {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    GameInfoViewController *gameInfoVC = (GameInfoViewController *)[storyboard instantiateViewControllerWithIdentifier:@"GameInfoViewController_ID"];

    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:gameInfoVC];
    _infoPopover = popover;
    [gameInfoVC setGameNameString:_gameNameLabel.attributedText];
}

[_infoPopover presentPopoverFromRect:_infoButton.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Run Code Online (Sandbox Code Playgroud)

谢谢!

xcode uipopovercontroller ios6 uicollectionview uicollectionviewcell

6
推荐指数
1
解决办法
3144
查看次数

将照片保存到相机胶卷时,AVCaptureMovieFileOutput导致方向错误

我对captureStillImageAsynchronouslyFromConnection有一个奇怪的问题.如果在镜像视频时使用jpegStillImageNSDataRepresentation保存图像,则相机胶卷中的图像顺时针旋转90度.但是,如果它没有镜像,则方向很好.我会发布代码,其他人有这个问题/知道修复?

更新:刚刚运行了一些测试,高度和宽度(640x480)很好,反映了设备的方向.当我以肖像拍照时,它会报告UIImageOrientationLeft并在镜像时报告UIImageOrientationLeftMirrored.

更新2:当我在相机胶卷中查看已保存的照片时,图像预览的方向正确,在照片之间滑动时图像也是如此,但是当照片完全加载时,它会旋转90度.这可能是相机胶卷问题吗?(我在4.3.3)

- (void) captureImageAndSaveToCameraRoll
{
    AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
    if ([stillImageConnection isVideoOrientationSupported])
        [stillImageConnection setVideoOrientation:[self orientation]];

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
                                                         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

                                                             ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
                                                                 if (error) {
                                                                     if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
                                                                         [[self delegate] captureManager:self didFailWithError:error];
                                                                     }
                                                                 }
                                                             };

                                                             if (imageDataSampleBuffer != NULL) {
                                                                 NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
                                                                 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

                                                                 UIImage *image = [[UIImage alloc] initWithData:imageData];
                                                                 [library writeImageToSavedPhotosAlbum:[image CGImage]
                                                                                           orientation:(ALAssetOrientation)[image imageOrientation]
                                                                                       completionBlock:completionBlock]; …
Run Code Online (Sandbox Code Playgroud)

iphone avfoundation ios avcapturesession avcam

5
推荐指数
1
解决办法
4249
查看次数

当附件是UITableViewCellAccessoryCheckmark时,如何在UITableViewCell中居中文本

当我将accessoryView设置为UITableViewCellAccessoryCheckmark时,我正在尝试将文本保持在UITableViewCell中心.我也在使用这个类的故事板.

这是我不想要的截图.

如何阻止文本向左缩进?

在此输入图像描述

我的willDisplayCell方法..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == [self cellToCheckmark]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        NSLog(@"Not Being Checked");
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

cell.textLabel.textAlignment = UITextAlignmentCenter;

    if (cell.shouldIndentWhileEditing == YES) {
        cell.shouldIndentWhileEditing = NO;
    }
}
Run Code Online (Sandbox Code Playgroud)

的cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = nil;

    static NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.textAlignment = UITextAlignmentCenter; …
Run Code Online (Sandbox Code Playgroud)

xcode uitableview ios5

5
推荐指数
2
解决办法
1万
查看次数

UICollectionViewCell会显示/显示?

非常简单的问题.

是否有通知或委托类型方法来判断何时显示UICollectionViewCell对象?

xcode ios6 uicollectionview uicollectionviewcell

5
推荐指数
2
解决办法
1万
查看次数

CAEmitterLayer:使用带有CAEmitterCell的@ 2x(视网膜)png图像

使用CAEmitterLayer,@ 2x(视网膜)图像不像iOS中的其他地方那样具有缩放属性.我得到的结果是@ 2x版本的显示尺寸是非视网膜图像的4倍,而不是按比例缩小.

知道怎么解决这个问题吗?我已经尝试在UIImageView中测试图像疼痛,结果是应该的,所以这似乎是CAEmitterLayer和CAEmitterCell的问题.图像具有正确的@ 2x.png说明符.

这是我正在使用的代码:

CAEmitterLayer *fallingCoinEmitter = [CAEmitterLayer layer];
fallingCoinEmitter.emitterPosition = CGPointMake(self.view.bounds.size.width / 2.0, -30);
fallingCoinEmitter.emitterSize = CGSizeMake(self.view.bounds.size.width * 2.0, 0.0);;

    // Spawn points for the flakes are within on the outline of the line
fallingCoinEmitter.emitterMode  = kCAEmitterLayerOutline;
fallingCoinEmitter.emitterShape = kCAEmitterLayerLine;

    // Configure the snowflake emitter cell
CAEmitterCell *coin = [CAEmitterCell emitterCell];
coin.birthRate      = 8.0;
coin.lifetime       = 5.0;
coin.velocity       = -180;             // falling down slowly
coin.velocityRange = 80;
coin.yAcceleration = 40;
coin.emissionRange = 0.4 * M_PI;        // some …
Run Code Online (Sandbox Code Playgroud)

xcode calayer ios caemitterlayer caemittercell

5
推荐指数
1
解决办法
1134
查看次数

从iOS的URL解析XML的最佳方法是什么?

我正在寻找在iOS上解析XML的最佳方法.似乎有很多方法可以做到这一点,有很多不同的例子.具体来说,我想向气象服务发送请求,然后从XML响应中提取天气.

如果你能指出我正确的方向,希望其他人也会觉得这很有用.

xml iphone ios

3
推荐指数
1
解决办法
5052
查看次数

是否最好在cellForRowAtIndexPath中使用if语句或switch语句? - UITableView

在UITableView中设置单元格时,最好使用if语句或switch语句作为一般做法吗?

我在这里特别谈论cellForRowAtIndexPath和其他UITableView方法,而不是一般的编程问题.

iphone objective-c uitableview ios4

2
推荐指数
1
解决办法
259
查看次数