c# - NSTimer - 适用于 iOS 10 但不适用于 iOS 9.3

标签 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 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]);
    }

});

这里是崩溃日志的详细信息:

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 -- 这是我为 NStimer 编写代码的代码行。

最佳答案

如果你在iOS项目中,你可以直接使用System.Threading.Timer。 如果你想在PCL工程中使用定时器,那么你可以引用这个链接:https://forums.xamarin.com/discussion/17227/timer-in-portable-class-library

关于c# - NSTimer - 适用于 iOS 10 但不适用于 iOS 9.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41310959/

相关文章:

c# - 这是生成一串随机字符的好方法吗?

c# - system.data.sqlite 的内存数据库包装器

objective-c - TBXML textForElement 问题

ios - CPU 运行率超过 100%

iphone - textFieldDidBeginEditing - 不工作

ios - 我可以在 info.plist 中定义用户定义的键吗

c# - .NET 运行时序列化

ios - 带有来自 plist 的数据的 objective-c 过滤 TableView

iphone - 将 CVImageBufferRef 转换为 CVPixelBufferRef

c# - 如何强制调试器跳过一段代码?