2016-12-24 6 views
1

Xamarinで開発されたiOSアプリケーションでNSTimerを使用しています。アプリはiOS 10(iPhone 5S)でもうまく動作していますが、iOS 9.3.5を搭載したiPadでクラッシュします。
なぜこのようなことが起こり、どうすれば解決できますか?NSTimer - iOS 10では動作しますが、iOSでは動作しません9.3

は、ここでは、コードです:

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ためのコードを持っているコードの行です。

+1

私はxamarinの人間ではありませんが、これはブロックベースのNSTimer APIに変換されているのでしょうか? iOS 10で導入された['scheduledTimer(withTimeInterval:repeats:block:)'](https://developer.apple.com/reference/foundation/timer/2091889-scheduledtimer))は、以前のiOSバージョンをサポートしようとしている場合は、「ターゲット」/「セレクタ」レンディションを使用します。 – Rob

+0

@Kyll okそれを得ました。 –

答えて

2

@Robが正しいです。 iOS 9をターゲットとする場合は、別の方法を使用する必要があります。

このコードは、IOSの10の前にIOSバージョンで利用できない新たブロック構文の実装に変換:

[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS、10、0、ObjCRuntime.PlatformArchitecture .None])、ヌル

https://developer.xamarin.com/api/member/Foundation.NSTimer.CreateScheduledTimer/p/System.Double/System.Boolean/System.Action%7BFoundation.NSTimer%7D/

+0

これまでのiOSバージョンで動作する代替方法はありますか? – Darshana

+0

@ダルサナ私の9.3アプリは簡単にNstimer with the Part! – UserID0908

関連する問題