[英]NSTimer - working on iOS 10 but not on iOS 9.3
I am using NSTimer
in my iOS app developed in Xamarin. 我在Xamarin开发的iOS应用程序中使用NSTimer
。 App is working fine on iOS 10 (iPhone 5S) but crashing on my iPad with with iOS 9.3.5. App在iOS 10(iPhone 5S)上运行正常,但在iOS 9.3.5上的iPad上崩溃。
Why is this happening and how can I fix it? 为什么会发生这种情况,我该如何解决?
Here's the code: 这是代码:
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]);
}
});
And here is the crash log detail: 这是崩溃日志的详细信息:
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)
LocationManager.cs:277
-- this is the code line where I have code for NStimer
. LocationManager.cs:277
NStimer
这是我拥有NStimer
代码的代码行。
You can directly use System.Threading.Timer
if you are in iOS project. 如果您在iOS项目中,则可以直接使用System.Threading.Timer
。 If you want to use the timer in a PCL project, then you can refer to this link: https://forums.xamarin.com/discussion/17227/timer-in-portable-class-library 如果要在PCL项目中使用计时器,则可以参考以下链接: https : //forums.xamarin.com/discussion/17227/timer-in-portable-class-library
@Rob is right. @Rob是对的。 You should use another methods if you're targeting iOS 9 or below. 如果您要定位的是iOS 9或更低版本,则应使用其他方法。
This code translates to the newly block-syntax implementation which is not available on iOS versions prior to iOS 10: 此代码转换为新的块语法实现,在iOS 10之前的iOS版本上不可用:
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 10, 0, ObjCRuntime.PlatformArchitecture.None, null)] [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS,10,0,ObjCRuntime.PlatformArchitecture.None,null)]
https://developer.xamarin.com/api/member/Foundation.NSTimer.CreateScheduledTimer/p/System.Double/System.Boolean/System.Action%7BFoundation.NSTimer%7D/ https://developer.xamarin.com/api/member/Foundation.NSTimer.CreateScheduledTimer/p/System.Double/System.Boolean/System.Action%7BFoundation.NSTimer%7D/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.