【问题标题】:iOS location using wifi networks使用 wifi 网络的 iOS 定位
【发布时间】:2015-10-28 08:54:02
【问题描述】:

我需要知道是否可以在 iOS 中使用 wifi 网络获取用户位置。

我了解了重大位置更改的方法,但我不知道用户是否有必要连接到无线网络,或者只是当 de 设备检测到事件周围有新的 wifi 网络时触发。

如您所见,我对主题一无所知,任何人都可以指导我一下吗?

【问题讨论】:

  • 我认为这不是你的工作。您需要做的就是获得归还给您的设备的协调员。我认为准确定位是 Apple 的事情。
  • 我所做的是,当用户进入一些 wifi 网络时,如果该网络是应用程序感兴趣的网络之一,则会提醒用户。

标签: ios geolocation location wifi


【解决方案1】:
Used Reachability class
@property (nonatomic) Reachability *hostReachability;
@property (nonatomic) Reachability *internetReachability;
@property (nonatomic) Reachability *wifiReachability;

Call below method in didFinishLaunchingWithOptions
-(void)makeConnectionOverRechability {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; //When intenet connectivity change this method call

    NSString *remoteHostName = @"www.apple.com";
    self.hostReachability = [Reachability reachabilityWithHostName:remoteHostName];
    [self.hostReachability startNotifier];
    [self updateInterfaceWithReachability:self.hostReachability];

    self.internetReachability = [Reachability reachabilityForInternetConnection];
    [self.internetReachability startNotifier];
    [self updateInterfaceWithReachability:self.internetReachability];

    self.wifiReachability = [Reachability reachabilityForLocalWiFi];
    [self.wifiReachability startNotifier];
    [self updateInterfaceWithReachability:self.wifiReachability];

}

#pragma mark-
#pragma mark Internect Connectivity
-(BOOL)checkInternetConnection
{
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.com"];
    NetworkStatus internetStatus = [reach currentReachabilityStatus];
    if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
    {
        return internetStatus;
    }
    return internetStatus;
}

- (void) reachabilityChanged:(NSNotification *)note
{
    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
    [self updateInterfaceWithReachability:curReach];
}

- (void)updateInterfaceWithReachability:(Reachability *)reachability
{
    if (reachability == self.hostReachability)
    {

    }
    if (reachability == self.internetReachability)
    {
        [self configureTextField:reachability];
    }

    if (reachability == self.wifiReachability)
    {
        [self configureTextField:reachability];
    }
}

- (void)configureTextField:(Reachability *)reachability
{
    NetworkStatus netStatus = [reachability currentReachabilityStatus];

//check here only wifi connection

    switch (netStatus)
    {
        case NotReachable:  {
            NSLog(@"not Connected+++++++++++");

            break;
        }
        case ReachableViaWWAN:  {
            NSLog(@"Connected");
                      break;
        }
        case ReachableViaWiFi: {
            NSLog(@"Connected");

            }
            break;
        }
}

【讨论】:

  • 首先,感谢您的帮助。我不理解您共享的所有代码。它应该检测到一个新的无线网络。它会要求用户登录网络吗?它可以在后台与应用程序一起使用吗?
  • else if (status == ReachableViaWWAN) { //2G, 3G,4G } ...在这里您可以检测网络。如果 ([kAppDelegateObject checkInternetConnection]) { }
  • (status == ReachableViaWWAN) { //3G ,2G
  • 应该有一些注释来解释所做的事情,而不是仅仅抛出代码。
猜你喜欢
  • 2011-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
  • 2014-04-08
  • 2013-02-28
相关资源
最近更新 更多