用于Iphone 4s的蓝牙LE应用程序的后台时间问题 [英] Background time issue for Bluetooth LE app for Iphone 4s

查看:228
本文介绍了用于Iphone 4s的蓝牙LE应用程序的后台时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Iphone-4s中为我的应用程序使用核心蓝牙框架。

这通常必须是一个可以尽可能长时间运行的后台应用程序。

I am using core-bluetooth framework for my app in Iphone-4s.
This is typically has to be a background app which can run as longer as possible.

现在它只运行40分钟 - 最多1小时。

Now it is only running for 40 min - 1 hour max.

我希望至少1天左右。

I am hoping for at least 1 day or so.

这个bluetooth-central值在.plist文件的Required background modes键中添加。

For this "bluetooth-central" value is added in "Required background modes" key in .plist file.

似乎我的应用程序最终将暂停模式。因为当我再次打开应用程序(背景到前景状态)时它再次发送通知,这意味着蓝牙连接仍然连接,并且BLE设备仍在发送通知。如果我按下主页按钮并且应用程序进入后台,则不会再次收到通知。

It seems like my app is going to "suspend" mode, at the end. since when I open the app again (background to foreground state) it is sending the notification again, it means the bluetooth connection is still connected and BLE-device is still sending notification. If i press home button and app comes to background, it does NOT get notification again.

任何人都可以告诉我为什么我的应用程序只能在后台模式下工作最多1小时。它应该像普通的音乐应用程序一样继续在后台运行,就像永远一样。

Can anybody tell me why my app live in background mode only for max 1 hour. It should continue run like normal music app in background for like forever.

Apple是否说明了背景应用程序(这是连续运行的背景之一)的具体条件失败的应用程序属于暂停模式吗?

Is Apple say anything specific about on which condition an background app (which is one of those continuous running background app falling with in the 5 categories) failing which it will go to suspend mode?

参考 iPhoneAppProgrammingGuide ,在与蓝牙附件进行通信部分,
我逐渐了解到,对于蓝牙LE应用2的长期运行后台任务,实现是必要的:

Referring "iPhoneAppProgrammingGuide", on "Communicating with a Bluetooth Accessory" section, I come to know that, for long running background task for Bluetooth LE application 2 implementations are necessory:

1)UIBackgroundModes键应该是 Info.plist 文件中的bluetooth-central。
2)任何支持蓝牙数据后台处理的应用程序都必须基于会话。

1) UIBackgroundModes key should be "bluetooth-central" in Info.plist file. 2) Any app that supports the background processing of Bluetooth data must be session-based.

因此对于我的应用程序,FIRST实现已合并,并且该应用程序能够在后台运行并执行
最长1小时的所有任务。

So for my app, the FIRST implementation was incorporated, and with that application is able to run in background and do all the tasks for max 1 hour duration.

现在我需要实现第二个实现。即基于会话的。根据文档,即使应用程序处于暂停状态
,也可以获取事件。我试图创建一个特定于蓝牙LE(核心蓝牙框架)的合适会话,例如经典蓝牙(外部附件框架)的
EASession 。但我没有找到它。

Now I need to implement 2nd implementation. i.e. session-based. Which will allow to get the events even if the app is in "suspend" state according to the documentation. I tried to find to create a suitable session specific to Bluetooth LE (Core Bluetooth framework) like the "EASession" present for Classic Bluetooth (External Accessory framework). But I did not find it.

基本上我不确定我需要将哪个会话类用于BLE目的。对于音频/视频,网络和互联网,外部配件,
有单独的会话类可用。 Core Bluetooth框架没有。

Basically I am not sure which session class i need to use for BLE purpose. For audio/video, networking and internet, external accessory, there are individual session class available. There is none for Core Bluetooth framework.

任何人都可以帮我,哪个会话类适合BLE。

Could anybody help me with, which session class is suitable for BLE.

推荐答案

我认为问题很简单,试着像我的屏幕一样实现你 info.plist

I think the problem is simple try to implement you info.plist like my screen:




和如果你愿意,可以在 didFinishLaunchingWithOptions 下的 AppDelegate.m 上添加该功能,以启用蓝牙,AirPlay WiFi等,这只是一个示例代码,但我认为可以帮助你。


And if you want you can add the function on AppDelegate.m under the didFinishLaunchingWithOptions to enable Bluetooth, AirPlay WiFi and more, this is only a example code, but i think can help you.

NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

希望这可以帮到你。

这篇关于用于Iphone 4s的蓝牙LE应用程序的后台时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆