如何使用MvvMCross在运行时检测平台

如何使用MvvMCross在运行时检测平台

本文介绍了如何使用MvvMCross在运行时检测平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户能够将有关我的应用程序的反馈发送到某个地址.使用电子邮件插件,这一切都很好,但是在电子邮件的正文中,我想预填充一些有关它们正在运行的应用程序的信息.

I want the user to be able to send feedback about my app to an address. Using the email plugin, this is all good, but in the body of the email, I want to pre-populate some information about the app they're running.

理想情况下,我想要设备,操作系统,屏幕分辨率,方向等,但是现在我只是选择操作系统

Ideally, I'd like the device, the OS, the screen res, the orientation etc, but for now I'd just settle for the OS

推荐答案

这感觉很奇怪,但是我不记得有人曾经要求将此作为功能,而且我也不认为有人为此而制作了插件.

It feels quite strange, but I can't remember anyone ever asking for this as a feature and I don't think anyone's made a plugin for it either.

鉴于您将来的需求(屏幕分辨率,方向等),最简单的方法可能是在核心项目中定义一个界面:

Given your future requirements (screen res, orientation, etc) the easiest way to this is probably to define an interface in your core project:

 public enum OS
 {
    Droid, Touch, WinPhone, WinStore, Mac, Wpf
 }

 public IDetails
 {
     OS OS { get; }
     // whatever else you need
 }

然后您可以在每个UI项目中为此注册实现-例如在Setup for WinPhone中,添加:

You can then register implementations for this in each UI project - e.g. in Setup for WinPhone, add:

 protected override void InitializeLastChance()
 {
     base. Setup.InitializeLastChance();
     Mvx.RegisterSingleton<IDetails>(new WindowsPhoneDetails());
 }

位置:

 public class WindowsPhoneDetails : IDetails
 {
     public OS OS { get { return OS.WinPhone; } }
 }

有关此方法的更多信息,请参见 https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup#wiki-registering-platform-specific-business-objects -setupinitializeizefirstchance和setupinitializeizelastchance

For more on this approach, see https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup#wiki-registering-platform-specific-business-objects-in-setupinitializefirstchance-and-setupinitializelastchance

(具体用于屏幕尺寸,另请参见 https://中的IDisplayDimensionsService github.com/MvvmCross/MvvmCross-Tutorials/tree/master/FractalGen )

(Specifically for screen size, also see IDisplayDimensionsService in https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/FractalGen)

这篇关于如何使用MvvMCross在运行时检测平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 14:48