“iPhone应用程序中的UIApplicationDelegate从未调用过回复()” - Xamarin

时间:2016-04-20 12:51:36

标签: ios iphone xamarin xamarin.ios watchkit

我正在尝试使用xamarin框架构建监视工具包应用程序并将其与我的iOS应用程序连接。在HandleWatchKitExtensionRequest中我使用MarketRequestHandler类来从API获取数据并将其显示在watchkit上。 我的错误是: “iPhone App中的UIApplicationDelegate从未调用reply() - [UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}     分类:{ObjCRuntime.Class}     ClassHandle(Foundation.NSError):0xf09c10     ClassHandle(Foundation.NSObject):0xf09c10     代码:2     DebugDescription:“Error Domain = com.apple.watchkit.errors Code = 2 \”iPhone App中的UIApplicationDelegate从未调用reply() - [UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:] \“UserInfo = {NSLocalizedDescription = UIApplicationDelegate in iPhone App永远不会调用reply() - [UIApplicationDelegate application:handleWatchKitExtensionRequest:reply:]}“

这是我的代码:

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 ();                




    }

观看界面

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());
        });


    }

1 个答案:

答案 0 :(得分:0)

查看您的代码,我猜测Observable会抛出id = json.ids[0];,因为之前您将其设置为空数组。这就是永远不会调用IndexOutOfRangeException的原因。也许你想在回调处理程序中使用reply而不是cb