小编Fel*_*lix的帖子

如何在iPad中使用UIImagePickerController?

嗨,我正在开发通用应用程序(iPhone/iPad).一个功能是我必须从相册中选择一张照片并在UIImageView上显示.

现在的问题是它在iPhone上运行良好但是当我尝试打开相册时它会崩溃.我在行动表委托中的代码是这样的:

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        if ( ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]))

        {   
            if (buttonIndex == 0)
            {
                [self lockAllImagesOnTheScreen];
                imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
                [self presentModalViewController:imagePicker animated:YES];
            }
            if (buttonIndex == 1)
            {
                [self lockAllImagesOnTheScreen];

                imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
                [self presentModalViewController:imagePicker animated:YES];
            }

        }
        else {

            if (buttonIndex == 0)
            {
                [self lockAllImagesOnTheScreen];
                imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
                imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
                [self presentModalViewController:imagePicker animated:YES];
            }
        }



    }

    else{
        if ( ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]))

        {   
            if (buttonIndex == 0)
            {
                [self lockAllImagesOnTheScreen];
                imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
                [self presentModalViewController:imagePicker animated:YES]; …
Run Code Online (Sandbox Code Playgroud)

iphone uiimagepickercontroller ipad

19
推荐指数
2
解决办法
3万
查看次数

在iOS中实现和排除背景音频

StackOverflow上有很多关于iOS背景音乐播放的问题.没有完全探索所有边缘情况,这个问题的目的是成为iOS背景音频问题的最后一个词

定义和假设

所有代码,问题和示例均参考.

"背景" - 当用户按下主页按钮或电源按钮时应用程序的状态(因此设备显示锁定屏幕).该应用程序还可以使用多任务切换器或iPad上的多任务手势进入后台.

"audio" - 使用AudioQueue播放的音频(包括AVAudioPlayer)

先决条件

据我了解,有一个要求让应用程序在后台播放音频.

  1. 设置UIBackgroundModesaudioInfo.plist
  2. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

要求

我的用例是在后台播放相对较长的音频(音乐).可能有数百个曲目,应用程序将按顺序播放它们.可以认为音频将无限播放.

该应用程序将通过暂停播放来处理中断.

问题

我的成功喜忧参半:

[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:...];
Run Code Online (Sandbox Code Playgroud)

允许音频在后台播放.但是我很困惑它是否需要以及它与以下内容的区别:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
Run Code Online (Sandbox Code Playgroud)

边缘案例

  1. 中断.如果您注册成为音频中断(电话等)的通知,则成为其代表AVAudioPlayer.例如,如果您在中断开始时暂停或停止音频,则在结束时恢复,如果中断超过10分钟(后台任务完成的最长时间),您的应用程序将被暂停?

  2. 如果调用Lock或Home,模拟器将停止音频,同时使用:

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    
    Run Code Online (Sandbox Code Playgroud)

但是这适用于设备.这是一个已知的问题?

iphone avaudioplayer audioqueue avaudiosession ios5

15
推荐指数
1
解决办法
2498
查看次数

两个iOS设备之间的通信

我正在寻找一种方法让一个iPhone应用程序发送消息到另一个手机上的另一个应用程序(有点像发件人接收器设置).我正在寻找最好的方法来做到这一点.有没有人有任何想法和/或教程?

谢谢您的帮助.

iphone networking communication ios

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

AFNetworking:enqueueBatchOfHTTPRequestOperations问题与完成块

我使用这种AFNetworking方法一次启动多个请求:

- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations 
                              progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock 
                            completionBlock:(void (^)(NSArray *operations))completionBlock
Run Code Online (Sandbox Code Playgroud)

其中一个是AFJSONRequestOperation.问题是此JSON操作的成功块是在批处理的完成块之后执行的.原因是:AFJSONRequestOperation有一个用于JSON处理的内部调度队列.因此,在调用完成块时,JSON数据仍在处理中.

问题:如何在调用JSON操作的成功块之后在完成块中执行代码?

我试图在主队列上调度代码块,但这没有帮助.

iphone nsoperation nsoperationqueue ios afnetworking

12
推荐指数
1
解决办法
3004
查看次数

适用于Xcode 6的XLIFF本地化工具

Xcode 6引入了一个新的本地化工作流程,它使用了开放的.XLIFF格式.Xcode从NSLocalizedString中提取字符串,在storyboards/XIB文件中提取字符串,并为每个本地化创建一个XLIFF文件.

我正在寻找好的本地化工具,翻译人员可以用它来打开和编辑Xcode导出的文件.

翻译后的文件需要保存为.XLIFF,然后导入Xcode.Xcode为XLIFF文件中指定的目标语言创建新的本地化或更新现有的本地化.

您推荐哪种本地化工具?

xcode localization nslocalizedstring xliff

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

本地化:如何获取当前的用户语言?

我即将本地化一个iPhone应用程序.当用户的语言(iOS系统语言)是德语时,我想使用不同的URL.

我想知道这是否是正确的方法:

NSURL *url = [NSURL URLWithString:@"http://..."]; // english URL
NSString* languageCode = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([languageCode isEqualToString:@"de"]) {
    url = [NSURL URLWithString:@"http://..."]; // german URL
}
Run Code Online (Sandbox Code Playgroud)

据我所知,[NSLocale currentLocale]返回基于当前区域的语言,但不是系统语言,也不起作用[NSLocale systemLocale].

(我不想在NSLocalizedString这里使用!)

iphone localization nslocale

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

UITableView中的错误(deleteSections:withRowAnimation:)?

我在使用这个UITableView方法时遇到问题:

- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
Run Code Online (Sandbox Code Playgroud)

首先文档说:

动画:YES表示删除部分的动画,否则为NO.

但参数动画实际上是枚举类型UITableViewRowAnimation,而不是BOOL!?

那么如何禁用动画呢?我试过NOUITableViewRowAnimationNone.什么都行不通.部分删除始终是动画的.

我知道我可以用[tableView reloadData].这将解决我的问题.我只是好奇这是否是一个已知问题,并且是否可以使用此tableview方法禁用动画.

谢谢!

iphone animation uitableview ios

9
推荐指数
2
解决办法
4711
查看次数

突然间我无法为iphone模拟器构建

有时人们想要真的讨厌Apple开发环境.说真的,这需要复杂吗?

我的问题是这个.我不再能够将我的项目构建到模拟器.我收到以下错误.我意识到这是一个链接器错误 - 我不明白的是1)为什么这突然不再起作用,2)为什么它不会选择正确的SDK(这是链接器错误的原因).

Apple Magik令人沮丧.

此外,我刚刚升级到Snow Leopard和XCode 3.2,虽然升级后它正在运行.

谢谢!布赖恩

Ld build/Debug-iphonesimulator/ChunderCats.app/ChunderCats normal i386
cd /Users/bryan/projects/iPhone/ChunderCats
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk -L/Users/bryan/projects/iPhone/ChunderCats/build/Debug-iphonesimulator -L/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib -F/Users/bryan/projects/iPhone/ChunderCats/build/Debug-iphonesimulator -F/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks -filelist /Users/bryan/projects/iPhone/ChunderCats/build/ChunderCats.build/Debug-iphonesimulator/ChunderCats.build/Objects-normal/i386/ChunderCats.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework QuartzCore -framework UIKit -framework CoreGraphics -lsqlite3 -o /Users/bryan/projects/iPhone/ChunderCats/build/Debug-iphonesimulator/ChunderCats.app/ChunderCats

ld: warning: in /Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/Foundation.framework/Foundation, missing required architecture i386 in file
ld: warning: in /Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore, missing required architecture i386 in file
ld: warning: in /Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/UIKit.framework/UIKit, missing required architecture i386 in file
ld: warning: in /Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics, missing …
Run Code Online (Sandbox Code Playgroud)

iphone xcode build ios-simulator

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

智能格式化时间跨度

我需要一种方法来将NSTimeInterval(以秒为单位的时间跨度)格式化为字符串,以产生类似"大约10分钟前","1小时,20分钟""小于1分钟"的内容.

-(NSString*) formattedTimeSpan:(NSTimeInterval)interval;
Run Code Online (Sandbox Code Playgroud)

目标平台是iOS.欢迎使用示例代码.

iphone formatting time objective-c

8
推荐指数
1
解决办法
3141
查看次数

在iOS6中控制MKMapView的动画速度

我正试图在地图视图上关注汽车.

此代码应以相同的速度为汽车和地图设置动画,以便注释视图始终显示在中心:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationBeginsFromCurrentState:YES];

[car setCoordinate:coord];
[mapView setCenterCoordinate:coord];

[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

它在iOS 5中运行良好.在iOS 6中,地图不再是动画,但汽车确实有动画效果.

我试过[mapView setCenterCoordinate:co animated:YES],但后来我无法控制动画速度.它将始终使用默认持续时间(0.2秒)进行动画处理.

iphone animation mkmapview ios ios6

8
推荐指数
3
解决办法
6361
查看次数