0

クロスプラットフォームの xamarin ソリューションで ibeacons を見つけるマルチプラットフォーム アプリの非常に単純な POC を取得しようとしています。私は物事のアンドロイド側を持っていますが、物事のiOS側で問題にぶつかっています.

私は AppDelegate クラスに次のハッキングされたコードを持っています (これは最初にそれをいじくり回すだけです。これは存在するべき場所ではないことに気付きました):

[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
    UIWindow window;

    static readonly string uuid = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
    static readonly string monkeyId = "Monkey";

    CBPeripheralManager peripheralMgr;
    BTPeripheralDelegate peripheralDelegate;
    CLLocationManager locationMgr;

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        window = new UIWindow(UIScreen.MainScreen.Bounds);

        myAppManagerApp.Init(typeof(myAppManagerApp).Assembly);
        Forms.Init();
       // FormsMaps.Init();            

        UINavigationBar.Appearance.BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0);
        UINavigationBar.Appearance.TintColor = UIColor.Blue;          
        UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
        {
            TextColor = UIColor.White
        });

        window.RootViewController = BuildView();
        window.MakeKeyAndVisible();

        var monkeyUUID = new NSUuid(uuid);
        var beaconRegion = new CLBeaconRegion(monkeyUUID, monkeyId);
        //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
        var power = new NSNumber(-59);
        NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power);
        peripheralDelegate = new BTPeripheralDelegate();
        peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
        peripheralMgr.StartAdvertising(peripheralData);

        locationMgr = new CLLocationManager();
        locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) =>
        {
            if (e.Region.Identifier == monkeyId)
            {
                var notification = new UILocalNotification() { AlertBody = "There's a monkey hiding nearby!" };
                UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
            }
        };

        locationMgr.DidStartMonitoringForRegion += locationMgr_DidStartMonitoringForRegion;
        locationMgr.MonitoringFailed += locationMgr_MonitoringFailed;

        locationMgr.StartMonitoring(beaconRegion);
        locationMgr.StartRangingBeacons(beaconRegion);

        locationMgr.DidRangeBeacons +=locationMgr_DidRangeBeacons;

        return true;
    }

    private void locationMgr_DidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
    {
            throw new NotImplementedException();
    }

    private void locationMgr_MonitoringFailed(object sender, CLRegionErrorEventArgs e)
    {
        throw new NotImplementedException();
    }

    private void locationMgr_DidStartMonitoringForRegion(object sender, CLRegionEventArgs e)
    {
        int i = 0;
        //throw new NotImplementedException();
    }

    static UIViewController BuildView()
    {
        var root = new pgeRoot();
        var controller = root.CreateViewController();
        return controller;
    }

Find the monkey のサンプルからほとんどのコードを削除しました。どちらにしても、DidRangeBeacons または RegionEntered イベントは発生しません。私はestimote iBeaconsを使用しているので、それが違いを生むかどうかわかりませんか?

ここで何が欠けているかについてのアイデアはありますか? plist に入れる必要がある許可または設定はありますか?

ありがとう

4

1 に答える 1

2

CLLocationManageriOS 8では、位置情報サービスを使用する許可を明示的に求める必要があります。これは、(RequestAlwaysAuthorization監視用) およびRequestWhenInUseAuthorization(測距用) メソッドです。また、iOS アプリの Info.plist ファイルに適切な ( NSLocationAlwaysUsageDescriptionand ) エントリが必要ですが、Xamarin でこれを行う方法は完全にはわかりません。NSLocationWhenInUseUsageDescription

于 2014-10-21T07:48:12.670 に答える