在Xamarin.Forms中,我们经常会根据各个平台的特性特殊处理一些需求,比如:读取应用的版本号。
在此也以读取应用版本号为例,练习DependencyService用法:
创建IPlatformInfoService接口:
1 using System; 2 using System.Collections.Generic; 3 using System.Text; 4 5 namespace XFPractice.Service 6 { 7 public interface IPlatformInfoService 8 { 9 10 /// <summary> 11 /// 获取应用版本 12 /// </summary> 13 /// <returns></returns> 14 string GetAppVersion(); 15 16 } 17 }