I am trying to build watch kit application and coect it with my iOS app, using xamarin framework.In HandleWatchKitExtensionRequest I use MarketRequestHandler class in order to bring data from API and display it on watchkit. My Error is: "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]} Class: {ObjCRuntime.Class} ClassHandle (Foundation.NSError): 0xf09c10 ClassHandle (Foundation.NSObject): 0xf09c10 Code: 2 DebugDescription: "Error Domain=com.apple.watchkit.errors Code=2 "The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]" UserInfo={NSLocalizedDescription=The UIApplicationDelegate in the iPhone App never called reply() in -[UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}"
This is my 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 ();
}
Watch interface
public override void Awake (NSObject context) {
// 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);
retu;
}
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());
});
}
