2017-12-22 13 views
0

오늘 동전 위주의 심볼을 얻은 다음 오늘은 오브젝트 요청을위한 웹 요청을하고 있습니다.Xamarin-iOS 오늘 위젯,로드 할 수없는 문제

다시로드 할 때마다 위젯이 뷰를 다시 그려서 WidgetPerformUpdate 메서드를 호출하여 1/10 위젯에서로드 할 수 없습니다.

위젯에 개체를 추가 할 때 앱이 debuged되었고 문제가 발생했습니다.

약 1 주 동안이 문제가 누적되었습니다. 오늘의 위젯 문서와 튜토리얼을 모두 읽었습니다. 아무데도 도움이되지 않습니다.

내가 무엇을해야할지 모르겠다.로드 할 수 없다는 것은 내 악몽이다.

내 TodawyWidgetViewController 코드가 있습니다.

using System; 
using System.Collections.Generic; 
using NotificationCenter; 
using Foundation; 
using UIKit; 
using CryptoCurrencyPCL.POCO; 
using CryptoCurrencyPCL.Middleware; 
using System.Linq; 
using System.Threading.Tasks; 
using CryptoCurrencyPCL.Extensions; 
using CryptoCurrencyPCL.Enums; 
using CoreGraphics; 
using Newtonsoft; 
using Newtonsoft.Json; 
using CryptoPCL.POCO; 

namespace CryptoTodayWidget 
{ 
    public partial class TodayViewController : UIViewController, INCWidgetProviding,IUITableViewDataSource,IUITableViewDelegate 
    { 
     NSUserDefaults userDefaults; 
     const string ReuseId = "currencyCellReuseId"; 
     List<CoinDetail> _coins; 
     List<CoinDetail> _cachedCoins; 
     List<FavoriteCoin> _favorites; 
     List<string> listOfStrings = new List<string>(); 
     Currency itemCurrency; 
     private CGSize _maxSize; 
     private string nsStringForValues; 
     private string nsString; 
     private List<string> deserializedObjectsSymbols; 
     bool _firstInit = true; 


     protected TodayViewController(IntPtr handle) : base(handle) 
     { 
      // Note: this .ctor should not contain any initialization logic. 
     } 

     public override void DidReceiveMemoryWarning() 
     { 
      // Releases the view if it doesn't have a superview. 
      base.DidReceiveMemoryWarning(); 

      // Release any cached data, images, etc that aren't in use. 
     } 

     public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
      var cell = tableView.DequeueReusableCell(ReuseId, indexPath) as WidgetCell; 

      var item = _coins[indexPath.Row]; 
      var favorite = _favorites[indexPath.Row]; 

      cell.InitData(item,favorite,itemCurrency); 

      return cell; 
     } 

     public nint RowsInSection(UITableView tableView, nint section) 
     { 
      return _coins?.Count ?? 0; 
     } 

     [Export("tableView:heightForRowAtIndexPath:")] 
     public nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) 
     { 
      return 50; 
     } 

     [Export("numberOfSectionsInTableView:")] 
     public nint NumberOfSections(UITableView tableView) 
     { 
      return 1; 
     } 

     public async override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 

      var webClient = CryptoCurrencyPCL.Services.CryptoWebClient.Instance; 
      tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; 

      _cachedCoins = _coins; 
      if(_coins != null) { 
       initTableView(); 
      } 

      ExtensionContext.SetWidgetLargestAvailableDisplayMode(NCWidgetDisplayMode.Expanded); 
     } 

     private void initTableView() 
     { 
      tableView.DataSource = this; 
      tableView.Delegate = this; 
      tableView.AllowsSelection = false; 
      tableView.ReloadData(); 
     } 

     public override void ViewDidAppear(bool animated) 
     { 
      base.ViewDidAppear(animated); 

     } 

     [Export("widgetPerformUpdateWithCompletionHandler:")] 
     public async void WidgetPerformUpdate(Action<NCUpdateResult> completionHandler) 
     { 
      var webClient = CryptoCurrencyPCL.Services.CryptoWebClient.Instance; 



      try 
      { 
       initLoading(); 
       bool check = false; 
       userDefaults = new NSUserDefaults("group.com.mpdc.todayextension", NSUserDefaultsType.SuiteName); 
       nsStringForValues = userDefaults?.StringForKey(new NSString("MyAppsValues")); 
       nsString = userDefaults?.StringForKey("currencyKey"); 
       itemCurrency = (Currency)Enum.Parse(typeof(Currency), nsString); 

       _favorites = JsonConvert.DeserializeObject<List<FavoriteCoin>>(nsStringForValues); 

       deserializedObjectsSymbols = _favorites.Select(o => o.FavoriteCoinSymbol).ToList(); 


       _coins = await webClient.GetMultiCoinDetailsAsync(deserializedObjectsSymbols, itemCurrency); 


       if (ExtensionContext.GetWidgetLargestAvailableDisplayMode() == NCWidgetDisplayMode.Compact) 
       { 

        this.PreferredContentSize =_maxSize; 
       } 

       else 
       { 
        this.PreferredContentSize = new CoreGraphics.CGSize(0, _coins.Count * 50); 
       } 

       initTableView(); 
       initLoading(false); 

       tableView.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine; 

       completionHandler(NCUpdateResult.NewData); 

      } 
      catch (Exception ex) 
      { 
       initLoading(false); 
       completionHandler(NCUpdateResult.Failed); 
       Console.WriteLine(ex); 
      } 

     } 


     void initLoading(bool visible = true) 
     { 

      if (visible) 
      { 
       ActivityIndicator.Hidden = false; 
       ActivityIndicator.StartAnimating(); 
       return; 
      } 

      ActivityIndicator.Hidden = true; 
      ActivityIndicator.StopAnimating(); 
     } 

     [Export("widgetActiveDisplayModeDidChange:withMaximumSize:")] 
     public void WidgetActiveDisplayModeDidChange(NCWidgetDisplayMode activeDisplayMode, CoreGraphics.CGSize maxSize) 
     { 
      _maxSize = maxSize; 

      if (activeDisplayMode == NCWidgetDisplayMode.Compact) 
      { 

       this.PreferredContentSize = _maxSize; 
      } 

      else 
      { 
       if(_coins!=null) 
       this.PreferredContentSize = new CoreGraphics.CGSize(0, _coins.Count * 50); 
      } 
     } 

    } 
} 

+0

문제를 확인하기 위해 크래시 코드를 게시 할 수 있습니다. 아마도 "CryptoCurrencyPCL"의 문제이거나 데이터를로드하는 데 너무 오래 걸립니다. 오늘 연장은 긴 작업에 사용되어서는 안되기 때문입니다. –

+0

아주 이상한 문제는 시뮬레이터에서 작동하지만 실제 장치에서는 작동하지 않는다는 것입니다. –

+0

시뮬레이터와 실제 장치 사이에는 약간의 차이점이 있습니다. 어쩌면 데이터가 너무 많아서 데이터 용량을 줄이고 다시 디버그하려고 시도했을 것입니다. –

답변

0

나는 그것을 해결 감사드립니다.

시뮬레이터에서는 작동하지만 장치에서는 작동하지 않습니다.

디버그 모드에서 장치에서 응용 프로그램을 실행할 때 문제가 발생했습니다.

디버그 모드에서는 메모리 문제가 발생했다고 생각합니다.

릴리스 모드로 실행했는데 모든 것이 작동합니다.