コード例 #1
0
        public IObservable <CompassReading> WhenReadingTaken()
        => this.readOb ??= Observable.Create <CompassReading>(ob =>
        {
            var handler = new EventHandler <CLHeadingUpdatedEventArgs>((sender, args) =>
            {
                var accuracy = this.FromNative(args.NewHeading.HeadingAccuracy);
                var read     = new CompassReading(accuracy, args.NewHeading.MagneticHeading, args.NewHeading.TrueHeading);
                ob.OnNext(read);
            });
            var lm = new CLLocationManager
            {
                DesiredAccuracy = CLLocation.AccuracyBest,
                HeadingFilter   = 1
            };
            lm.UpdatedHeading += handler;
            lm.StartUpdatingHeading();

            return(() =>
            {
                lm.StopUpdatingHeading();
                lm.UpdatedHeading -= handler;
            });
        })
        .Publish()
        .RefCount();
コード例 #2
0
        public IObservable <CompassReading> WhenReadingTaken()
        => this.readOb ??= Observable.Create <CompassReading>(ob =>
        {
            var handler = new TypedEventHandler <Compass, CompassReadingChangedEventArgs>((sender, args) =>
            {
                var accuracy = this.FromNative(args.Reading.HeadingAccuracy);
                var read     = new CompassReading(accuracy, args.Reading.HeadingMagneticNorth, args.Reading.HeadingTrueNorth ?? 0);
                ob.OnNext(read);
            });
            this.compass.ReadingChanged += handler;

            return(() => this.compass.ReadingChanged -= handler);
        })
        .Publish()
        .RefCount();