无法封送objective-c对象

时间:2017-10-13 16:18:30

标签: c# ios xamarin xamarin.ios kontakt.io

我遇到以下错误时遇到了困难:

  

无法编组Objective-C对象0x17109780(类型:   SMBSC_iOS_EddystoneManagerDelegate)。找不到现有的   此对象的托管实例,也无法创建新对象   托管实例(因为类型   'SMBSC.iOS.EddystoneManagerDelegate'没有构造函数   采用一个IntPtr参数。)

我已添加了它正在寻找的构造函数,但应用程序仍然因此错误而崩溃。

我正在使用Kontakt Xamarin component

我正在创建一个包含以下行的新扫描:

manager = new KTKEddystoneManager(new EddystoneManagerDelegate() { ScanID = ID });

以下是导致错误的委托:

 public class EddystoneManagerDelegate : KTKEddystoneManagerDelegate
    {
        public static int closestRssi { get; set; }
        public static string closestInstance { get; set; }

        public int ScanID { get; set; }

        public EddystoneManagerDelegate()
        {

        }

        public EddystoneManagerDelegate(IntPtr handle) : base(handle)
        {

        }

        public override void DidFailToStartDiscovery(KTKEddystoneManager manager, NSError error)
        {
            Console.WriteLine("Eddystone discovery failed with error: " + error.Description);
        }

        public override void DidUpdateEddystone(KTKEddystoneManager manager, KTKEddystone eddystone, KTKEddystoneFrameType frameType)
        {
            string bkpnt = "";
        }

        public override void DidDiscoverEddystones(KTKEddystoneManager manager, NSSet<KTKEddystone> eddystones, KTKEddystoneRegion region)
        {
            try
            {
                Console.WriteLine("");
                Console.WriteLine("------------------------------------------------------------------------");
                Console.WriteLine("------------------------------------------------------------------------");
                Console.WriteLine("------------------------------------------------------------------------");

                int i = 0;
                foreach (SavedPoint p in App.discoveredBeaconList)
                {
                    i += 1;
                    Console.WriteLine("Existing Beacon List: " + p.BeaconInstanceID + " - " + p.BeaconTruckDesc + " - " + p.RSSI);
                }
                if (App.closestBeaconForTracking != null)
                {
                    Console.WriteLine("Selected Beacon Before Logic: " + App.closestBeaconForTracking.instanceID + " RSSI: " + App.closestBeaconForTracking.RSSI);
                }
                else
                {
                    Console.WriteLine("Selected Beacon Before Logic: no beacon selected");
                }

                App.singleOutputValue = "";

                Console.WriteLine("Discovered " + eddystones.Count + " eddystones");

                App.beaconTimer = DateTime.Now;
                App.trackingBeaconTimer = DateTime.Now;

                MessagingCenter.Send<App>(App.instance, "Output");

                if (eddystones.Count == 1)
                {
                    TimeSpan span = DateTime.Now - EddystoneiOS.StartTime;

                    Console.WriteLine("First Stone found in " + span.TotalSeconds + " seconds");

                    App.outputValue += "    First Stone found in " + span.TotalSeconds + " seconds; " + ScanID + ";    " + DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine;

                    MessagingCenter.Send<App>(App.instance, "Output");
                }
                else if (eddystones.Count == 2)
                {
                    TimeSpan span = DateTime.Now - EddystoneiOS.StartTime;

                    Console.WriteLine("Second Stone found in " + span.TotalSeconds + " seconds");

                    App.outputValue += "    Second Stone found in " + span.TotalSeconds + " seconds; " + ScanID + ";    " + DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine;

                    MessagingCenter.Send<App>(App.instance, "Output");
                }
                else if (eddystones.Count == 3)
                {
                    TimeSpan span = DateTime.Now - EddystoneiOS.StartTime;

                    Console.WriteLine("Third Stone found in " + span.TotalSeconds + " seconds");

                    App.outputValue += "    Third Stone found in " + span.TotalSeconds + " seconds; " + ScanID + ";    " + DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine;

                    MessagingCenter.Send<App>(App.instance, "Output");
                }
                else if (eddystones.Count == 4)
                {
                    TimeSpan span = DateTime.Now - EddystoneiOS.StartTime;

                    Console.WriteLine("Fourth Stone found in " + span.TotalSeconds + " seconds");

                    App.outputValue += "    Fourth Stone found in " + span.TotalSeconds + " seconds; " + ScanID + ";    " + DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine;

                    MessagingCenter.Send<App>(App.instance, "Output");
                }

                App.closestBeaconForTracking = null;

                foreach (var stone in eddystones)
                {
                    KTKEddystone eddystone = (KTKEddystone)stone;

                    Console.WriteLine(eddystone.RSSI + ", " + eddystone.EddystoneUID.InstanceID);

                    App.outputValue += "            " + eddystone.RSSI + ", " + ScanID + ";    " + eddystone.EddystoneUID.InstanceID + Environment.NewLine;

                    App.instanceID = eddystone.EddystoneUID.InstanceID;

                    App.NameSpaceID = eddystone.EddystoneUID.NamespaceID;

                    App.rssi = eddystone.RSSI.Int32Value;

                    App.BeaconCount = (int)eddystones.Count;

                    App.lastBeaconTime = DateTime.Now.ToString();

                    if (App.isViewingBeacons)
                    {
                        MessagingCenter.Send<App>(App.instance, "StoneForBeaconList");
                    }

                    MapApp.Beacon beacon = App.Database.GetBeaconByID(eddystone.EddystoneUID.InstanceID.ToLower(), eddystone.EddystoneUID.NamespaceID.ToUpper());

                    if (beacon != null)
                    {
                        beacon.RSSI = eddystone.RSSI.Int32Value;
                        SavedPoint point = new SavedPoint() { BeaconID = beacon.BeaconID, BeaconInstanceID = beacon.instanceID, BeaconName = beacon.Name, BeaconNameSpaceID = beacon.namespaceID, RSSI = beacon.RSSI, BeaconTruckDesc = beacon.truckDesc };

                        point.LastSeenTime = DateTime.Now;

                        if (App.discoveredBeaconList == null)
                        {
                            App.discoveredBeaconList = new List<SavedPoint>();
                        }

                        if (!App.discoveredBeaconList.Exists(x => x.BeaconInstanceID == point.BeaconInstanceID) && beacon.RSSI != 0)
                        {
                            App.discoveredBeaconList.Add(point);
                        }
                        else
                        {
                            foreach (SavedPoint p in App.discoveredBeaconList)
                            {
                                if (p.BeaconInstanceID == point.BeaconInstanceID && beacon.RSSI != 0)
                                {
                                    p.LastSeenTime = DateTime.Now;
                                    p.RSSI = point.RSSI;
                                }
                            }
                        }
                    }

                    if (eddystone.RSSI.Int32Value != 0)
                    {
                        if (string.IsNullOrWhiteSpace(App.closestBeaconOutput))
                        {
                            App.closestBeaconOutput = eddystone.EddystoneUID.InstanceID + " " + eddystone.RSSI;
                            closestRssi = (int)eddystone.RSSI;
                            closestInstance = (string)eddystone.EddystoneUID.InstanceID;

                            MessagingCenter.Send<App>(App.instance, "topOutput");
                        }

                        if (closestInstance == eddystone.EddystoneUID.InstanceID)
                        {
                            App.closestBeaconOutput = eddystone.EddystoneUID.InstanceID + " " + eddystone.RSSI;
                            closestRssi = (int)eddystone.RSSI;
                            closestInstance = (string)eddystone.EddystoneUID.InstanceID;

                            MessagingCenter.Send<App>(App.instance, "topOutput");
                        }

                        if ((int)eddystone.RSSI > closestRssi)
                        {
                            App.closestBeaconOutput = eddystone.EddystoneUID.InstanceID + " " + eddystone.RSSI;
                            closestRssi = (int)eddystone.RSSI;
                            closestInstance = (string)eddystone.EddystoneUID.InstanceID;

                            MessagingCenter.Send<App>(App.instance, "topOutput");
                        }

                        //if(App.closestBeaconForTracking == null)
                        //{
                        //    App.closestBeaconForTracking = App.Database.GetBeaconByID(eddystone.EddystoneUID.InstanceID.ToLower(), eddystone.EddystoneUID.NamespaceID.ToUpper());
                        //    if(App.closestBeaconForTracking != null)
                        //    {
                        //        App.closestBeaconForTracking.RSSI = (int)eddystone.RSSI;
                        //    }
                        //}

                        //if (App.closestBeaconForTracking != null)
                        //{
                        //    if (App.closestBeaconForTracking.instanceID.ToLower() == eddystone.EddystoneUID.InstanceID && App.closestBeaconForTracking.namespaceID.ToLower() == eddystone.EddystoneUID.NamespaceID)
                        //    {
                        //        App.closestBeaconForTracking.RSSI = (int)eddystone.RSSI;
                        //    }

                        //    if (eddystone.RSSI.Int32Value > App.closestBeaconForTracking.RSSI)
                        //    {
                        //        App.closestBeaconForTracking = App.Database.GetBeaconByID(eddystone.EddystoneUID.InstanceID.ToLower(), eddystone.EddystoneUID.NamespaceID.ToUpper());
                        //        if (App.closestBeaconForTracking != null)
                        //        {
                        //            App.closestBeaconForTracking.RSSI = (int)eddystone.RSSI;
                        //        }
                        //    }
                        //}
                    }

                    SavedPoint flipPoint = new SavedPoint();
                    //if(App.discoveredBeaconList.Count > 1)
                    //{
                    //    try
                    //    {
                    //        if (App.discoveredBeaconList[0].BeaconInstanceID != App.closestBeaconForTracking.instanceID)
                    //        {
                    //            App.discoveredBeaconList.Insert(1, App.discoveredBeaconList[1]);
                    //            App.discoveredBeaconList[0].BeaconInstanceID = App.closestBeaconForTracking.instanceID;
                    //            App.discoveredBeaconList[0].BeaconNameSpaceID = App.closestBeaconForTracking.namespaceID;
                    //            App.discoveredBeaconList[0].BeaconID = App.closestBeaconForTracking.BeaconID;
                    //            App.discoveredBeaconList[0].RSSI = App.closestBeaconForTracking.RSSI;
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        throw new Exception("Error in App.discoveredBeaconList.Count > 1");

                    //    }
                    //}

                    //if(App.discoveredBeaconList.Count > 1)
                    //{
                    //    if(App.discoveredBeaconList[0].RSSI > App.closestBeaconForTracking.RSSI)
                    //    {
                    //        App.closestBeaconForTracking.instanceID = App.discoveredBeaconList[0].BeaconInstanceID;
                    //        App.closestBeaconForTracking.namespaceID = App.discoveredBeaconList[0].BeaconNameSpaceID;
                    //        App.closestBeaconForTracking.RSSI = App.discoveredBeaconList[0].RSSI;
                    //        App.closestBeaconForTracking.truckDesc = App.discoveredBeaconList[0].BeaconTruckDesc;
                    //    }
                    //}
                    App.singleOutputValue += eddystone.EddystoneUID.InstanceID + " " + eddystone.RSSI.Int32Value + "; ";
                }

                if (App.discoveredBeaconList.Count > 0)
                {
                    SavedPoint topBeacon = App.discoveredBeaconList.OrderByDescending(c => c.RSSI).First();

                    MapApp.Beacon convertedBeacon = new MapApp.Beacon();
                    convertedBeacon.RSSI = topBeacon.RSSI;
                    convertedBeacon.Name = topBeacon.BeaconName;
                    convertedBeacon.namespaceID = topBeacon.BeaconNameSpaceID;
                    convertedBeacon.instanceID = topBeacon.BeaconInstanceID;
                    convertedBeacon.BeaconID = topBeacon.BeaconID;
                    convertedBeacon.truckDesc = topBeacon.BeaconTruckDesc;

                    App.closestBeaconForTracking = convertedBeacon;
                }

                if (App.closestBeaconForTracking != null)
                {
                    Console.WriteLine("Selected Beacon: " + App.closestBeaconForTracking.instanceID + " RSSI: " + App.closestBeaconForTracking.RSSI);

                    MapApp.Beacon beacon = App.Database.GetBeaconByID(App.closestBeaconForTracking.instanceID, App.closestBeaconForTracking.namespaceID);

                if(!string.IsNullOrWhiteSpace(beacon.truckDesc))
                {
                    App.catchTruckDesc = beacon.truckDesc;
                    //Insights.Identify(App.catchTruckDesc);
                }
            }
            else
            {
                Console.WriteLine("Selected Beacon: no beacon selected");
            }
            Console.WriteLine("------------------------------------------------------------------------");
            Console.WriteLine("------------------------------------------------------------------------");
            Console.WriteLine("------------------------------------------------------------------------");
            Console.WriteLine("");

                //if (App.closestBeaconForTracking != null && !string.IsNullOrWhiteSpace(App.closestBeaconForTracking.instanceID))
                //{
                //    App.singleOutputValue = "Beacon found at: " + DateTime.Now + Environment.NewLine + App.closestBeaconForTracking.instanceID + " " + App.closestBeaconForTracking.RSSI;
                //}

                MessagingCenter.Send<App>(App.instance, "singleOutput");

                MessagingCenter.Send<App>(App.instance, "UpdateStartText");

                MessagingCenter.Send<App>(App.instance, "Output");
            }
            catch (Exception ex)
            {
                if (string.IsNullOrWhiteSpace(App.catchFieldDesc))
                {
                    App.catchFieldDesc = "Null";
                }
                if (string.IsNullOrWhiteSpace(App.catchTruckDesc))
                {
                    App.catchTruckDesc = "Null";
                }

                Insights.Report(ex, new Dictionary<string, string>() { { "DidDiscoverEddystone", ex.StackTrace }, { "Field Description", App.catchFieldDesc }, { "Truck Description", App.catchTruckDesc } }, Insights.Severity.Critical);
            }           
        }

我在互联网上做了一些搜索,但我没有发现任何与我的场景相关的内容。我确定我的代码有错误,但我不完全理解这个错误。

我已经读过这个错误可能是由Garbage Collector收集对象引起的。

这个错误究竟是什么意思,我可以看一下尝试修复?

谢谢!

0 个答案:

没有答案