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

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

问题描述

我创建了使用iOS版iBeacons一个应用程序。我知道,如果我所监控的区域,这个框架可以调用我的应用程序,当我进入/退出的区域,或关闭区域内的屏幕上。我已经成功地创建这个回调本地通知为好。
我的问题是,是否有可能使应用到前台,一样,如果它是由用户启动的?


解决方案

没有,我不相信这是可能的。苹果的理念是,用户在什么应用程序是在前台控制。仅有的三个方法,把一个应用程序到前台有:(1)攻其图标,(2)攻与应用程序或相关的通知(3)通过自定义URL以启动从不同的应用程序中的应用。

我有谁一直坚称这是可能的一个同事,所以我想今天我看到的肯定。在我们的开源 SavengerHunt应用,我修改了AppDelegate中的 didDetermineState 方法添加下面的code,试图迫使应用程序推向前台。

 的NSLog(@试图为部队窗口%@到前台,self.window);
        [self.window makeKeyAndVisible]
        的NSLog(@与试图完成);

在code时在后台检测到iBeacon显示,日志线出现了按预期执行。该应用程序,但是,并没有改变前台。

  2014年3月6日11:35:43.655 scavengerhunt [277:60B]发送通知灯塔附近
       2014年3月6日11:35:43.678 scavengerhunt [277:60B]试图对力窗LT;一个UIWindow:0x14e96730;帧=(0 0 320 480); gestureRecognizers =<的NSArray:0x14e95870取代;层= LT; UIWindowLayer:0x14e961f0>>到前台
       2014年3月6日11:35:43.686 scavengerhunt [277:60B]完成与尝试

由于这是不行的,你最好的赌注是present本地通知用户。如果他们在其上敲击,你的应用程序将移至前台。

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?

解决方案

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.

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");

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天全站免登陆