I am trying to build watch kit application and connect 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);
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());
});
}
Looking at your code, I would guess that id = json.ids[0];
throws an IndexOutOfRangeException
since previously you set it to an empty array. That's why reply
is never called. Perhaps you wanted to use cb
instead of json
in the callback handler.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.