当我进入 iBeacon 范围时,我可以在前台启动应用程序吗? [英] Can I launch an app in Foreground when I enter an iBeacon range?

查看:17
本文介绍了当我进入 iBeacon 范围时,我可以在前台启动应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iBeacons 为 iOS 创建一个应用程序.我知道,如果我设置一个区域进行监控,框架可以在我进入/退出一个区域时调用我的应用程序,或者打开该区域内的屏幕.我也设法在这个回调中创建了一个本地通知.我的问题是,是否可以将应用程序置于前台,就像它是由用户启动的一样?

I'm creating an app for iOS using iBeacons. I know, that if i set up a region to monitor, the framework can invoke my app when I enter/exit a region, or turn on the screen inside the region. I've managed to create a local notification in this callback as well. My question is, whether is it possible to bring the app into foreground, like if it was launched by the user?

推荐答案

不,我不相信这是可能的.Apple 的理念是用户可以控制前台的应用程序.将应用程序置于前台的唯一三种方法是:(1) 点按其图标,(2) 点按与应用程序关联的通知,或 (3) 通过自定义 URL 从其他应用程序启动应用程序.

No, I do not believe this is possible. Apple's philosophy is that the user is in control of what app is in the foreground. The only three ways to bring an app into the foreground are: (1) tapping its icon, (2) tapping a notification associated with the app or (3) through a custom URL to launch the app from a different app.

我有一位同事一直坚持认为这是可能的,所以我今天自己尝试了一下,以确定是否可以.在我们的开源 SavengerHunt app 中,我修改了 AppDelegate 的 didDetermineState 方法添加下面的代码以尝试强制应用程序进入前台.

I have a colleague who has long insisted this is possible, so I tried it myself today to see for sure. In our open source SavengerHunt app, I modified the AppDelegate's didDetermineState method to add the code below to try and force the app into the foreground.

        NSLog(@"Attempting for force window %@ into foreground", self.window);
        [self.window makeKeyAndVisible];
        NSLog(@"Done with attempt");

在后台检测到 iBeacon 时执行的代码,并且日志行按预期显示.但是,该应用程序并未切换到前台.

The code executed when an iBeacon was detected in the background, and the log lines showed up as expected. The app, however, did not change to the foreground.

       2014-03-06 11:35:43.655 scavengerhunt[277:60b] Sending a notification that a beacon is nearby
       2014-03-06 11:35:43.678 scavengerhunt[277:60b] Attempting for force window <UIWindow: 0x14e96730; frame = (0 0; 320 480); gestureRecognizers = <NSArray: 0x14e95870>; layer = <UIWindowLayer: 0x14e961f0>> into foreground
       2014-03-06 11:35:43.686 scavengerhunt[277:60b] Done with attempt

鉴于这不起作用,您最好的办法是向用户显示本地通知.如果他们点击它,您的应用将移至前台.

Given that this doesn't work, your best bet is to present a local notification to the user. If they tap on it, your app will move to the foreground.

这篇关于当我进入 iBeacon 范围时,我可以在前台启动应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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