Tag: Objective C

iPhone XMPP应用程序运行的背景

我创build了一个使用XMPP框架的聊天应用程序。当我退出应用程序(进入后台模式),我想接收聊天消息,并且还需要显示图标徽章…我该怎么做?

如何检测iPhone中按下键盘键?

每当用户按下任何键盘按键,我都要检测。 任何仅在键入任何字符时才调用的方法,而不是在显示键盘时调用。 谢谢!!

AVCaptureSession和背景audioiOS 7

每当我开始一个运行麦克风的AVCaptureSession作为input时,它将取消当前正在运行的任何背景音乐(例如iPod音乐)。 如果我将添加audioinput的行注释掉,背景audio会继续。 有没有人知道用麦克风录制video剪辑的方法,同时继续播放背景audio? 当您尝试录制video和音乐正在播放时,也有错误。 试图这样做: [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil]; UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); [[AVAudioSession sharedInstance] setActive: YES error: nil]; 但 'AudioSessionSetProperty' is deprecated: first deprecated in iOS 7.0 所以我试图这样做: AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *setCategoryError = nil; [audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&setCategoryError]; [audioSession setActive:YES error:nil]; 但最后它没有工作。 感谢帮助!

UINavigationController强制旋转

我的应用程序主要是肖像,但有一个视图需要横向。 我的意见是包含在一个UINavigationController,这(显然)是这个问题的原因。 所有UIViewControllers除了一个有这样的: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } 需要横向的UIViewController有这样的: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); } 现在,当用户到达横向UIViewController时会发生什么情况,它是以纵向显示的。 用户可以旋转他们的手机,并根据需要显示在横向(locking到横向)。 用户然后继续前进到一个肖像UIViewController,同样的情况发生:它开始在横向,然后他们旋转他们的手机,并再次成为肖像(locking肖像)。 看起来方向locking是允许的UIViewControllers之间,但自动旋转/编程方式改变方向以某种方式被阻止。 如何强制手机更新到正确的方向? 有一个临时的解决scheme:我可以检测设备的方向,并显示一条消息,要求他们旋转设备,如果不正确,但这不是最佳的。

循环访问NSAttributedString属性以增加字体

我所需要的是循环遍历NSAttributedString所有属性,并增加它们的字体大小。 到目前为止,我已经到了成功循环和操作属性的地步,但是我不能保存回NSAttributedString 。 我注意到的线路不适合我。 如何保存? NSAttributedString *attrString = self.richTextEditor.attributedText; [attrString enumerateAttributesInRange: NSMakeRange(0, attrString.string.length) options:NSAttributedStringEnumerationReverse usingBlock: ^(NSDictionary *attributes, NSRange range, BOOL *stop) { NSMutableDictionary *mutableAttributes = [NSMutableDictionary dictionaryWithDictionary:attributes]; UIFont *font = [mutableAttributes objectForKey:NSFontAttributeName]; UIFont *newFont = [UIFont fontWithName:font.fontName size:font.pointSize*2]; [mutableAttributes setObject:newFont forKey:NSFontAttributeName]; //Error: [self.richTextEditor.attributedText setAttributes:mutableAttributes range:range]; //no interfacce for setAttributes:range: }];

UIScrollView里面的UITableView在滚动后没有收到第一个水龙头

简要 我在UIScrollView里有一个UITableView的问题。 当我滚动外部滚动scrollView , table在第一次触摸时不会接收到willSelect/didSelect事件,但它在第二次触摸时会发生。 更奇怪的是,即使delegate没有,单元本身也会得到触动和突出显示的状态。 详细的解释 我的视图层次: UIView – UIScrollView (outerscroll) – Some other views and buttons – UITableView (tableView) 在滚动视图中,我有一些额外的视图dynamic扩展/closures。 表视图需要与视图的其他元素一起“固定”在顶部,所以这就是为什么我创build了这个布局,这使我能够以类似的方式轻松地移动元素,而不是像Apple推荐的那样通过使用转换滚动发生。 当outerscroll像这样移动时,表格View被转换为翻译效果: – (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.outerScrollView) { CGFloat tableOffset = scrollView.contentOffset.y – self.fixedHeaderFrame.origin.y; if (tableOffset > 0) { self.tableView.contentOffset = CGPointMake(0, tableOffset); self.tableView.transform = CGAffineTransformMakeTranslation(0, tableOffset); } else { […]

将iPhone应用程序转换为Xcode 4中的通用应用程序

我正在尝试将现有的iPhone应用程序项目升级到通用应用程序,但在Xcode 4中找不到任何选项。 它在哪里?

获取系统卷iOS

我的情况很简单:我需要发出一个警告信号,并要确保用户会听到它,所以我想检查系统音量。 我怎样才能找出当前的系统容量是多less?

录制audio并永久保存在iOS中

我已经做了2个iPhone应用程序,可以录制audio并将其保存到文件并再次播放。 其中一个使用AVAudiorecorder和AVAudioplayer。 第二个是苹果公司的SpeakHereaudio队列的例子。 既可以在Simulater上运行,也可以在Device上运行。 但当我重新启动任何应用程序logging的文件没有find! 我已经尝试了所有可能的build议在stackoverflow上find,但它仍然无法正常工作! 这是我用来保存文件: NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound1.caf"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

iOS:让应用程序在后台运行

如何让我的应用程序在后台运行? 我将不得不越狱我的iPhone做到这一点? 我只需要这个应用程序来检查每一个设定的时间间隔在互联网上的东西,并在需要时通知我自己使用。