gpt4 book ai didi

ios - Xamarin Estimote 找不到适用于 iOS 的信标

转载 作者:行者123 更新时间:2023-11-28 21:56:08 25 4
gpt4 key购买 nike

我只是想获得我的多平台应用程序的一个非常简单的 POC,在跨平台 xamarin 解决方案中查找 ibeacon。我已经了解了 Android 方面的事情,但只是遇到了 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 中吗?

谢谢

最佳答案

在 iOS 8 中,您需要明确请求许可才能使用位置服务 - 这是 CLLocationManagerRequestAlwaysAuthorization(用于监控)和 RequestWhenInUseAuthorization(用于测距)方法。您还需要在您的 iOS 应用程序的 Info.plist 文件中有一个适当的 (NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription) 条目,但我不确定如何在 Xamarin 中执行此操作。

关于ios - Xamarin Estimote 找不到适用于 iOS 的信标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26479408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com