【发布时间】:2016-12-24 06:32:55
【问题描述】:
我在用 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 代码的代码行。
【问题讨论】:
-
我不是 xamarin 人,但我想知道这是否会转化为 iOS 10 中引入的基于块的
NSTimerAPI(请参阅scheduledTimer(withTimeInterval:repeats:block:))。您必须使用如果您要支持早期的 iOS 版本,请使用旧的target/selector再现。 -
@Kyll 好的。
标签: c# ios iphone xamarin.ios nstimer