Tag: 背景

相当于Android服务的iOS?

所以iOS 7支持更广泛的背景模式,是否有可能在iOS上终于有一个相当于Android的服务? 我所追求的基本上是在后台运行应用程序A,并有一个或多个应用程序B和C与该应用程序交谈(不显示应用程序A的GUI)。 请注意,使用连接和推送通知可能不是一个选项,虽然这是推荐的方式。 有任何想法吗?

iOS应用程序在后台录制时audio中断

我的iPad声音应用程序(iOS 7.1)能够在后台录制。 只要在后台录制不中断,一切都可以。 例如,如果有人(愚蠢?)的想法,开始听音乐,而录音的东西。 我试图以不同的方式pipe理这种中断,但没有成功。 问题是, – (void)audioRecorderEndInterruption:(AVAudioPlayer *)p withOptions:(NSUInteger)flags 当应用程序在后台发生中断时,永远不会被触发。 然后,我尝试在另一个解决scheme中实现AVAudioSessionInterruptionNotification和handleInterruption:方法 – (void) viewDidAppear:(BOOL)animated { …… AVAudioSession *session=[AVAudioSession sharedInstance]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:session]; ……. } // interruption handling – (void)handleInterruption:(NSNotification *)notification { try { UInt8 theInterruptionType = [[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] intValue]; NSLog(@"Session interrupted > — %s —\n", theInterruptionType == AVAudioSessionInterruptionTypeBegan ? "Begin Interruption" […]

在后台iOS应用中播放audio

我有一个应用程序主要基于核心蓝牙。 当某些具体事情发生时,应用程序被唤醒使用核心蓝牙背景模式,它会发出警报,但是当应用程序不在前台时,我无法使警报工作。 我有一个Alarm Singleton类,它初始化AVAudioPlayer像这样: NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundName ofType:@"caf"]]; self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; [self.player prepareToPlay]; self.player.numberOfLoops = -1; [self.player setVolume:1.0]; NSLog(@"%@", self.player); 这是调用我的闹钟代码时调用的方法: -(void)startAlert { NSLog(@"%s", __FUNCTION__); playing = YES; [self.player play]; NSLog(@"%i", self.player.playing); if (vibrate) { [self vibratePattern]; } […]

swift / ios在后台刷新应用程序数据

我正在写一个iOS / Swift应用程序,每隔X分钟从REST服务读取数据并相应地更新UI。 现在,我希望当应用程序放在后台时,从REST服务读取X分钟间隔的任务,并且在刚刚读取的数据满足给定条件的情况下继续调用任务,显示通知提示用户将应用程序回到前台。 在我的search中,我已经阅读了applicationDidEnterBackground事件,我应该用beginBackgroundTaskWithExpirationHandler启动一个任务。 问题是,如果我理解正确,这最多可以允许10/15分钟,如果任务不是以endBackgroundUpdateTask停止的话,应用程序将被终止,而我希望任务能够无限期地持续轮询服务(至less直到用户从应用程序的设置中禁用它) 我的问题是: 这种function如何正常执行? 解决这个问题是否存在一些共同的解决scheme或最佳实践?

iOS – AVAudioPlayer在后台不会继续播放下一首歌曲

所以我有一个应用程序,播放一堆歌曲,而用户可以翻阅一本漫画书。 我使用AVAudioPlayer,并设置了播放歌曲的顺序。 所以当一首歌完成后,下一首将会播放。 这应用程序打开时,完美的工作。 当应用程序在后台时发生问题。 我设置了应用程序在后台播放,而且工作正常。 所以当用户按下主屏幕时,音乐继续播放。 问题发生在歌曲结束时,应该打开应用程序时播放下一首歌曲。 相反,没有发生。 根据我的NSLog语句正确的方法被调用,但没有任何反应。 这是我的代码: – (void)audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully: (BOOL) flag { NSLog(@"Song finished"); if ([songSelect isEqualToString: @"01icecapades"]) { isPlay = @"yes"; songSelect = @"02sugarcube"; imageSelect = @"playbanner02"; [self performSelector:@selector(triggerSong) withObject:nil afterDelay:0]; [self performSelector:@selector(triggerBanner) withObject:nil afterDelay:0]; } else if ([songSelect isEqualToString: @"02sugarcube"]) { isPlay = @"yes"; songSelect = […]

检测背景中的可达性

我一直在testing不同的方式来实现的可能性,以知道设备上网时,它的应用程序是在后台,所以我testing的第一个代码是苹果的可达性示例代码http://developer.apple.com/library/ios /#samplecode/Reachability/Introduction/Intro.html 但是这个代码在后台应用程序中不会通知互联网状态。 所以我也尝试了下面的代码,当App从Background状态启动到前台时(与Apple可达性示例代码相同) – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // check for internet connection [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil]; // Set up Reachability internetReachable = [[Reachability reachabilityForInternetConnection] retain]; [internetReachable startNotifier]; … } – (void)applicationDidEnterBackground:(UIApplication *)application { // check for internet connection [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil]; // Set up Reachability internetReachable = […]

为什么CSS background-size:cover在iOS的纵向模式下不工作?

我试图在各种设备上设置一个手动的splash-image 。 我这样做是通过检查orientation (触摸设备)或screen width vs. screen height (无触摸)并相应地设置一个URL。 然后我通过Javascript添加这个CSS规则: document.styleSheets[3].insertRule('.initHandler:before { background: url('+x+') no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }', 0) x是根据方向和屏幕大小加载的图像。 我的问题是这在landscape模式下工作正常,但在portrait模式下我的iPad,加载正确的图像(根据不同的肖像/风景),但它没有扩大到全屏尺寸。 问题 : 我不能在纵向模式下的iOS上使用CSS background-size吗? 感谢帮助! 编辑: 刚试过我的Android智能手机。 在那里工作很好。 没有意义,为什么它不适用于iPad。

在后台运行iOS App超过10分钟

我试图让我的应用程序在后台运行10分钟以上,根据这个和我的好以下。 (我想使用长时间的背景运行来跟踪一个位置,我的代码在这里只是使用计数器进行testing)任何人都可以帮忙指出问题所在? 实施长期运行的后台任务 对于需要更多执行时间来执行的任务,您必须请求特定的权限才能在后台运行它们,而不会被暂停。 在iOS中,只有特定的应用程序types才能在后台运行: 在后台播放可听内容的应用,例如音乐播放器应用 随时向用户通知其位置的应用,例如导航应用 支持网际协议语音(VoIP)的应用 需要下载和处理新内容的报亭应用程序从外部附件获得定期更新的应用程序 实现这些服务的应用程序必须声明它们支持的服务,并使用系统框架来实现这些服务的相关方面。 声明这些服务可以让系统知道你使用了哪些服务,但是在某些情况下,系统框架确实会阻止你的应用程序被挂起。 – (void)viewDidLoad { [super viewDidLoad]; counterTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ }]; count=0; theTimer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(countUp) userInfo:nil repeats:YES]; } – (void)countUp { { count++; NSString *currentCount; currentCount=[[NSString alloc] initWithFormat:@"%ld",count]; theCount.text=currentCount; [currentCount release]; } } 另一个问题:我可以让iOS应用程序永远在后台运行吗? —-编辑的代码添加位置,仍然不会运行超过10分钟,对我做错了什么帮助? – (void)viewDidLoad { [super viewDidLoad]; count=0; locationManager = […]

iOS:ModalView与背景透明?

我想在viewController上显示一个模态视图。 (其中有一个naviguation控制器)。 在我看来,我有文字,和一个button来显示模态视图。 我创build了一个包含我的模态视图的.xib(这是一个带有图像和标签的视图)。 当我展示它时, ShareController *controller = [[ShareController alloc] initWithNibName:@"ShareController" bundle: nil]; controller.view.backgroundColor = [UIColor clearColor]; controller.modalPresentationStyle = UIModalPresentationFormSheet; controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:controller animated:YES completion:nil]; 我有我的modalview,但是,背景变成黑色..我想总是看到我的观点上的文字。 (我试图设置阿尔法,等..;但没有运行:'() 有人帮我? 谢谢,

iOS计时器在后台

我想在我的iOS应用程序启动一个计时器,当应用程序在后台运行,当应用程序closures。 定时器必须每隔30分钟检查一次新的通知。 在计时器function中,他们每30分钟调用另一个函数showNotification()。 我该如何做这个计时器,以及在应用程序未在后台运行/运行时,我必须在哪个位置调用计时器。