简体   繁体   English

Xamarin Forms iOS如何将应用程序带到前台-其他应用程序做到了

[英]Xamarin Forms iOS how to bring app to foreground - other apps do it

I'm working on my Xamarin Forms app. 我正在使用Xamarin Forms应用程序。 It needs to bring itself to the foreground once its been backgrounded using location services (background mode) after a while. 一段时间后,使用定位服务(后台模式)将其置于后台后,它需要将自己置于前台。 How can this be achieved? 如何做到这一点?

I notice other apps do it in the app store. 我注意到其他应用程序也在应用程序商店中执行此操作。

Any help would be much appreciated! 任何帮助将非常感激! Thanks 谢谢

You can use startMonitoringSignificantLocationChanges to achieve this. 您可以使用startMonitoringSignificantLocationChanges实现此目的。

In the apple document https://developer.apple.com/documentation/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati it writes: 在苹果文件https://developer.apple.com/documentation/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati中,它写道:

If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. 如果您启动此服务,而您的应用程序随后被终止,则当新事件到来时,系统会自动将应用程序重新启动到后台。 In such a case, the options dictionary passed to the application( :willFinishLaunchingWithOptions:) and application( :didFinishLaunchingWithOptions:) methods of your app delegate contains the key location to indicate that your app was launched because of a location event. 在这种情况下,传递给您的应用程序委托的application( :willFinishLaunchingWithOptions :)和application( :didFinishLaunchingWithOptions :)方法的选项字典包含关键位置,以指示由于位置事件而启动您的应用程序。 Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. 重新启动后,您仍然必须配置位置管理器对象并调用此方法以继续接收位置事件。 When you restart location services, the current event is delivered to your delegate immediately. 当您重新启动位置服务时,当前事件将立即传递给您的委托。 In addition, the location property of your location manager object is populated with the most recent location object even before you start location services. 此外,甚至在您启动位置服务之前,位置管理器对象的location属性也会使用最新的位置对象进行填充。

After relaunch, you can do something in FinishedLaunching in AppDelegate: 重新启动后,您可以在AppDelegate的FinishedLaunching中执行以下操作:

 public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocationKey))
            {
                // do something here after the app awaked
            }

            return true;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM