我在iOS和Android中学习应用程序开发,在搜索之后我不确定我是否得到了答案:我想构建一个基本上在其他用户(相同用户)时提醒用户的应用程序app)就在附近。如果他们有共同的兴趣(以前用户填写某种形式),则会发出警报。我在Stack Overflow中找到了这段代码,但我不确定它是否能完成这项工作。任何人都可以给我一些提示吗?
- (void) activateProximitySensor {
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;
if (device.proximityMonitoringEnabled == YES) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChanged:) name:@"UIDeviceProximityStateDidChangeNotification" object:device];
}
}
- (void) proximityChanged:(NSNotification *)notification {
UIDevice *device = [notification object];
NSLog(@"Detectat");
//DO WHATEVER I WANT
}
答案 0 :(得分:0)
在这种情况下,接近监测与检测光线水平的传感器有关(在前置扬声器正上方的iPhone上),这用于确定手机何时握住人耳或更换屏幕亮度取决于光线水平。
您可能会对此答案感兴趣How to detect nearby devices with Bluetooth LE in iOS 7.1 both in background and foreground?。
否则,您需要跟踪设备的GPS坐标并将其广播给其他客户。