Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NSTimer-在iOS 10上工作,但不在iOS 9.3上工作_C#_Ios_Iphone_Xamarin.ios_Nstimer - Fatal编程技术网

C# NSTimer-在iOS 10上工作,但不在iOS 9.3上工作

C# NSTimer-在iOS 10上工作,但不在iOS 9.3上工作,c#,ios,iphone,xamarin.ios,nstimer,C#,Ios,Iphone,Xamarin.ios,Nstimer,我正在Xamarin开发的iOS应用程序中使用NSTimer。该应用程序在iOS 10(iPhone 5S)上运行良好,但在iOS 9.3.5的iPad上崩溃。 为什么会发生这种情况?我如何修复它 代码如下: timer = NSTimer.CreateScheduledTimer(0.3, true, delegate { List<String> keys = this.beaconRegions.Keys.ToList(); foreach (string id

我正在Xamarin开发的iOS应用程序中使用
NSTimer
。该应用程序在iOS 10(iPhone 5S)上运行良好,但在iOS 9.3.5的iPad上崩溃。
为什么会发生这种情况?我如何修复它

代码如下:

timer = NSTimer.CreateScheduledTimer(0.3, true, delegate
{
    List<String> keys = this.beaconRegions.Keys.ToList();
    foreach (string identifier in keys)
    {
        this.locationManager.StopRangingBeacons((CLBeaconRegion)this.beaconRegions[identifier]);
        this.locationManager.StopMonitoring(this.beaconRegions[identifier]);
        this.locationManager.StartMonitoring(this.beaconRegions[identifier]);
        this.locationManager.StartRangingBeacons(this.beaconRegions[identifier]);
    }

});
timer=NSTimer.CreateScheduledTimer(0.3,true,委托
{
List keys=this.beaconRegions.keys.ToList();
foreach(键中的字符串标识符)
{
this.locationManager.StopRangingBeacons((CLBeaconRegion)this.beaconRegions[identifier]);
this.locationManager.StopMonitoring(this.beaconRegions[identifier]);
this.locationManager.StartMonitoring(this.beaconRegions[identifier]);
this.locationManager.StarTrangBeacons(this.beaconRegions[identifier]);
}
});
下面是崩溃日志的详细信息:

4   CoreFoundation                  0x21c9a234 0x21c72000 + 164404

5   iBeacon                         0x0023564c wrapper_managed_to_native_ObjCRuntime_Messaging_objc_msgSend_intptr_intptr_double_bool_intptr (/<unknown>:1)

6   iBeacon                         0x001e8ecc Foundation_NSTimer_CreateScheduledTimer_double_bool_System_Action_1_Foundation_NSTimer (NSTimer.g.cs:134)

7   iBeacon                         0x001de5b4 iBeacon_LocationManager_turnOnMonitoring (LocationManager.cs:277)

8   iBeacon                         0x001de2ac iBeacon_LocationManager_startMonitoringForBeacons (LocationManager.cs:250)
4 CoreFoundation 0x21c9a234 0x21c72000+164404
5 iBeacon 0x0023564c包装器\u托管\u到\u本机\u对象运行时\u消息传递\u对象运行\u msgSend\u intptr\u intptr\u双布尔\u intptr(/:1)
6 iBeacon 0x001e8ecc基础\u NSTimer\u CreateScheduledTimer\u double\u bool\u System\u Action\u 1\u基础\u NSTimer(NSTimer.g.cs:134)
7 iBeacon 0x001de5b4 iBeacon\u LocationManager\u turnOnMonitoring(LocationManager.cs:277)
8 iBeacon 0x001de2ac iBeacon\u LocationManager\u startMonitoringForBeacons(LocationManager.cs:250)

LocationManager.cs:277
——这是我为
NStimer

@Rob编写代码的代码行。如果您的目标是iOS 9或更低版本,则应使用其他方法

此代码转换为新的块语法实现,在iOS 10之前的iOS版本中不可用:

[ObjCRuntime.imported(ObjCRuntime.PlatformName.iOS,10,0,ObjCRuntime.PlatformArchitecture.None,null)]


@Rob是对的。如果您的目标是iOS 9或更低版本,则应使用其他方法

此代码转换为新的块语法实现,在iOS 10之前的iOS版本中不可用:

[ObjCRuntime.imported(ObjCRuntime.PlatformName.iOS,10,0,ObjCRuntime.PlatformArchitecture.None,null)]


如果您在iOS项目中,您可以直接使用
System.Threading.Timer

如果您想在PCL项目中使用计时器,则可以参考此链接:

如果您在iOS项目中,则可以直接使用
System.Threading.timer

如果您想在PCL项目中使用计时器,那么您可以参考以下链接:

我不是xamarin人,但我想知道这是否会转化为iOS 10中引入的基于块的
NSTimer
API(请参阅)。如果要支持早期的iOS版本,必须使用旧的
目标
/
选择器
格式副本。@Kyll ok明白了。我不是xamarin人,但我想知道这是否会转化为iOS 10中引入的基于块的
NSTimer
API(请参阅)。如果要支持早期的iOS版本,您必须使用旧的
目标
/
选择器
格式副本。@Kyll好的。好的,那么有什么替代方法可以在早期的iOS版本上工作呢?@darshana My 9.3应用程序可以轻松地处理问题部分给出的Nstimer!好的,那么有什么替代方法可以在以前的iOS版本上工作呢?@darshana我的9.3应用程序已经很容易地解决了问题部分给出的Nstimer!