【问题标题】:Does simulator supports background modes模拟器是否支持后台模式
【发布时间】:2013-09-05 07:45:29
【问题描述】:

如何启动后台语音进程。模拟器是否支持 iOS 中的后台模式。

这是我启动后台进程的代码。但它不起作用。当我按下主页按钮时,录制停止。

-(void)applicationDidEnterBackground:(UIApplication *)application
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //Check if our iOS version supports multitasking I.E iOS 4
        if ([[UIDevice currentDevice] isMultitaskingSupported]) { //Check if device supports multitasking
            UIApplication *application = [UIApplication sharedApplication]; //Get the shared application instance
            __block UIBackgroundTaskIdentifier background_task; //Create a task object
            background_task = [application beginBackgroundTaskWithExpirationHandler: ^ {
                [application endBackgroundTask: background_task]; //Tell the system that we are done with the tasks
                background_task = UIBackgroundTaskInvalid; //Set the task to be invalid
                //System will be shutting down the app at any point in time now
            }];
            //Background tasks require you to use asyncrous tasks
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                //Perform your tasks that your application requires
                NSLog(@"\n\nRunning in the background!\n\n");
                NSString *pollingTimer2 = [NSTimer scheduledTimerWithTimeInterval:1
                                                                           target:self
                                                                         selector:@selector(recordPauseTapped:)
                                                                         userInfo:nil
                                                                          repeats:YES];
                [application endBackgroundTask: background_task]; //End the task so the system knows that you are done with what you need to perform
                background_task = UIBackgroundTaskInvalid; //Invalidate the background_task
            });
        }
    }

}

【问题讨论】:

标签: ios objective-c


【解决方案1】:

要检查设备是否支持多任务,请使用以下代码:-

if ([[UIDevice currentDevice] isMultitaskingSupported])

虽然模拟器有一些硬件限制,包括:-

-加速度计
-陀螺仪
-相机
-接近传感器
-麦克风输入
要在设备上测试您的应用,您必须是 iOS 开发者计划的成员。要了解有关注册 iOS 开发者计划的更多信息,请参阅 App Distribution Guide 中的“注册 Apple Developer Program 并访问其工具”。 您无法在模拟器上测试所有这些功能

【讨论】:

  • @pooja_chaudhary 好像你和在这里回答的“pooja chaudhary”是同一个人。请仅使用一个帐户。
【解决方案2】:

不,它不支持后台模式。

【讨论】:

    【解决方案3】:

    模拟器支持后台模式,但是您的条件(如下)将在模拟器上失败,因此会出现问题。

    if ([[UIDevice currentDevice] isMultitaskingSupported])

    【讨论】:

    • 那我应该如何检查模拟器上的后台模式
    • 无论模拟器或设备如何,您都可能需要配置代码才能执行。删除检查设备功能的条件或为模拟器添加其他条件。
    • 你有没有在这个方法中设置一个断点并检查它是否在模拟器上执行?
    • 是的,这段代码在模拟器上执行,但实际上它不起作用
    【解决方案4】:

    是的,模拟器支持后台模式,但您必须在项目设置中启用它。您建议查看下面的链接。

    Background download sample

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 2016-01-21
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 2020-08-07
      相关资源
      最近更新 更多