所以我在visual studio 2017中使用xamarin.forms测试MobileFirst样本, 和iPhone模拟器:iPhone 7 Plus iOS 10.3(使用虚拟机)
这是代码:
public async void ObtainToken()
{
try
{
WorklightClient = App.WorklightClient;
WorklightAccessToken accessToken = await WorklightClient.AuthorizationManager.ObtainAccessToken("");
if (accessToken.Value != null && accessToken.Value != "")
{
System.Diagnostics.Debug.WriteLine("Received the following access token value: " + accessToken.Value);
await DisplayAlert("Token Value", accessToken.Value, "OK");
StringBuilder uriBuilder = new StringBuilder().Append("/adapters/javaAdapter/resource/greet");
WorklightResourceRequest request = WorklightClient.ResourceRequest(new Uri(uriBuilder.ToString(), UriKind.Relative), "GET");
request.SetQueryParameter("name", "world!");
WorklightResponse response = await request.Send();
System.Diagnostics.Debug.WriteLine("Success: " + response.ResponseText);
DisplayAlert("Greeting Get Request", response.ResponseText.ToString(), "OK");
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("An error occurred: '{0}'", e);
}
}
在访问第一行之前是craches(在调试中) 我不确定它是xamarin错误还是实例化worklighclient 错误:
2017-07-03 12:41:02.461 XamarinMFPTest.iOS[4642:52640] Will try to create a instance if null
2017-07-03 12:53:52.310 XamarinMFPTest.iOS[4642:52640] [FATAL] [WORKLIGHT] App Crash: Crashed with signal SIGSEGV (code SEGV_MAPERR)
ps:此代码正在运行android和uwp