简体   繁体   English

Xamarin表单:使用Azure的Win Phone 8.1 Silverlight脱机模式

[英]Xamarin Forms: Win Phone 8.1 Silverlight offline mode using Azure

I am creating an app that must be able to load when it is offline, for this we are using Azure and Sqlite. 我正在创建一个脱机时必须能够加载的应用程序,为此,我们正在使用Azure和Sqlite。 In the project I have downloaded the Microsoft.WindowsAzure.MobileServices.SQLiteStore package from NuGet along with its dependency package SQLitePCL. 在项目中,我从NuGet下载了Microsoft.WindowsAzure.MobileServices.SQLiteStore程序包及其依赖项程序包SQLitePCL。 These packages are added to the PCL, android, ios and win phone projects. 这些软件包已添加到PCL,Android,iOS和Win Phone项目中。 In ios and android everything works like a charm, however, in windows phone the reference "SQLite for Windows Phone (SQLite.WP80, Version 3.8.7.2)" added by SQLitePCL comes broken and when trying to build the project it throws the error "Could not find SDK SQLite.WP80, version=3.8.7.2". 在ios和android中,一切正常运行,但是,在Windows Phone中,由SQLitePCL添加的参考“ SQLite for Windows Phone(SQLite.WP80,版本3.8.7.2)”已损坏,并且在尝试构建项目时会抛出错误“找不到SDK SQLite.WP80,版本= 3.8.7.2”。 I have tried downloading older versions from NuGet to see if there is working version but I have had no luck. 我尝试从NuGet下载旧版本,以查看是否有可用的版本,但是我没有运气。 I also attempted removing this reference and adding it to the project externally downloading it through Visual Studio extensions and then adding the downloaded extension to the project solving the issue that the reference is broken. 我还尝试删除此引用,并将其添加到项目中,然后通过Visual Studio扩展从外部下载它,然后将下载的扩展添加到项目中,以解决引用被破坏的问题。 The version added is newer than NuGets since I was unable to find the same version. 添加的版本比NuGets更新,因为我找不到相同的版本。 The external references version is "SQLite for Windows Phone (SQLite.WP80, version=3.10.2)". 外部参考版本是“用于Windows Phone的SQLite(SQLite.WP80,版本= 3.10.2)”。 It now compiles correctly but when the code reaches the point of execution that requires this reference it throws the following error "This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.". 现在,它可以正确编译,但是当代码到达需要此引用的执行点时,它将引发以下错误“此程序集的可移植版本未实现此功能。您应该从主应用程序项目中引用NuGet包,以便请参考特定于平台的实现。”。 More specifically this error is thrown when the following code executes: 更具体地说,执行以下代码时将引发此错误:

if (!CrossConnectivity.Current.IsConnected)

Does anyone know how I can get this reference working since it seems to be broken in NuGet and it doesnt allow me to add it externally? 有谁知道我如何使该参考有效,因为它在NuGet中似乎已损坏,并且不允许我在外部添加它?

UPDATE 更新

Added some screen captures of the packages I have in NuGet and the projects they are in (All the projects except the common and api project). 添加了一些我在NuGet中拥有的软件包及其所在项目的屏幕截图(除common和api项目以外的所有项目)。 Also in the Screen captures I put an image of all the references in the PCL and WinPhone projects. 同样在屏幕截图中,我在PCL和WinPhone项目中放置了所有引用的图像。 The only reference that isnt in the PCL are the ones specifically for windows, one of these being the reference to "SQLite for Windows (SQLite.WP80, version=3.10.2)" mentioned in the link you provided. PCL中唯一不存在的引用是专门用于Windows的引用,其中之一是对您提供的链接中提到的“用于Windows的SQLite(SQLite.WP80,版本= 3.10.2)”的引用。

当前在所有项目中添加的Azure NuGet程序包

当前在所有项目中添加的SQLitePCL NuGet软件包

PCL参考

WinPhone参考

I couldn't find a solution to fix the reference itself but since the code only crashed when checking the phones connectivity I decided to look up another way to check this and came up with the following: 我找不到解决该引用本身的解决方案,但是由于该代码仅在检查电话连接时崩溃,因此我决定寻找另一种方法进行检查,并提出了以下解决方案:

if (!NetworkInterface.GetIsNetworkAvailable())

Hope this is helpful if someone else runs into this issue! 希望这对其他人有帮助!

To check the network status maybe you can use this in stead of CrossConnectivity.Current.IsConnected 要检查网络状态,您可以使用它代替CrossConnectivity.Current.IsConnected

using Xamarin.Forms;
using System.Net;
using System.Threading.Tasks;
using Plugin.Connectivity;

namespace XXXXXX
{
    public class NetworkHelper
    {
        #region CONSTANTS
        //2.5f
        private const float NETWORK_TIMEOUT_LIMIT = 3f; // Seconds
        private const String testUrl = "https://google.com/";
        #endregion

        public NetworkHelper ()
        {
        }

        #region PUBLIC METHODS
        public static bool CheckNetworkStatus()
        {
            bool bSuccess = false;

            try
            {
                var request = HttpWebRequest.Create(testUrl);
                request.Timeout = (int)TimeSpan.FromSeconds(NETWORK_TIMEOUT_LIMIT).TotalMilliseconds;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        Console.WriteLine("Error");
                        bSuccess = false;
                    }
                    else
                    {
                        bSuccess = true;
                    }
                }
            }
            catch (Exception ex)
            {
                bSuccess = false;
            }

            return bSuccess;
        }

        public static async Task<bool> IsRemoteReachable()
        {
            return await CrossConnectivity.Current.IsRemoteReachable("https://ccc.seeforge.com");
        }


        #endregion
    }
}

//Example:
var isNetworkConnected = await CheckNetworkStatus();

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

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