2016-04-20 4 views
0

Ich versuche Watch Kit-Anwendung zu erstellen und verbinden Sie es mit meiner iOS App, mit Xamarin Framework.In HandleWatchKitExtensionRequest Ich benutze MarketRequestHandler-Klasse, um Daten aus bringen API und zeige es auf Watchkit an. Mein Fehler ist: „Die UIApplicationDelegate in der iPhone App nie Antwort() in genannt - [UIApplicationDelegate Anwendung: handleWatchKitExtensionRequest: Antwort:]} Klasse: {ObjCRuntime.Class} ClassHandle (Foundation.NSError): 0xf09c10 ClassHandle (Foundation.NSObject): 0xf09c10 Code: 2 DebugDescription: "Fehler domain = com.apple.watchkit.errors Code = 2 \" Das UIApplicationDelegate in der iPhone App rief nie reply() in - [UIApplicationDelegate-Anwendung: handleWatchKitExtensionRequest: antwort: ] \ UserInfo = {NSLocalizedDescription = Das UIApplicationDelegate in der iPhone App hat nie reply() aufgerufen in - [UIApplicationDelegate application: handleWatchKitExtensionRequest: reply:]} ""Die UIApplicationDelegate in der iPhone App rief nie antwort()" - Xamarin

Dies ist mein Code:

public override void HandleWatchKitExtensionRequest 
    (UIApplication application, NSDictionary userInfo, Action<NSDictionary> reply) { 

     var json = new JsonParams(); 
     var id=""; 
     nint taskID = UIApplication.SharedApplication.BeginBackgroundTask (() => { 
     }); 
     new Task (() =>{ 
      MarketRequestHandler mrk = new MarketRequestHandler(); 

      json.ckeys = new string[]{"P"}; 
      json.ids = new string[0]; 
      json.fields = new string[]{ 
             "LastDealTime", 
             "LastDealDate" 
             }; 
      json.index = 0; 
      json.count = 300; 

      var jsonStr = JsonConvert.SerializeObject (json); 

      mrk.HandleRequest("market.get",jsonStr, (cb) =>{ 
       id = json.ids[0]; 
       reply (new NSDictionary (
        "index", NSNumber.FromInt32 ((int)json.index), 
        "count", NSNumber.FromInt32((int)json.count), 
        "rzf", new NSString(id) 
       )); 
      }); 
      UIApplication.SharedApplication.EndBackgroundTask(taskID); 
     }).Start();     




    } 

Uhr Schnittstelle

public override void Awake (NSObject Kontext) {

 // Configure interface objects here. 
     base.Awake (context); 
     Console.WriteLine ("{0} awake with context", this); 

     WKInterfaceController.OpenParentApplication (new NSDictionary(), (replyInfo, error) => { 
      if(error != null) { 
       Console.WriteLine (error); 
       return; 
      } 
      Console.WriteLine ("parent app responded"); 
      // do something with replyInfo[] dictionary 
      Label.SetText (replyInfo.Keys[0].ToString() + " " + replyInfo.Values[0].ToString()); 
      label2.SetText(replyInfo.Keys[1].ToString() + " " + replyInfo.Values[1].ToString()); 
      label3.SetText(replyInfo.Keys[2].ToString() + " " + replyInfo.Values[2].ToString()); 
     }); 


    } 

Antwort

0

auf den Code der Suche, ich würde vermuten, dass id = json.ids[0]; ein IndexOutOfRangeException wirft seit zuvor hast du es auf ein leeres Array gesetzt. Deshalb wird reply nie aufgerufen. Vielleicht wollten Sie cb anstelle von json im Callback-Handler verwenden.