2015-10-28 45 views
0

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

我阅读有关该方法的显著位置的变化,但我不知道这是否是必要的,用户在去设备检测周围的事件的新的wifi网络触发连接到无线网络或干脆。

正如你所看到的我不知道这个问题,任何人都可以指导我一点?

+0

我不认为这是你的工作。所有你需要做的是获得哪些设备返回给你的coordiantes。我认为这是苹果的事情,以准确的位置。 – ronan

+0

我所做的是这样的,当用户进入一些无线网络时,如果网络对应用感兴趣,则提醒用户。 –

回答

-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; 
     } 
} 
+0

首先,感谢您的帮助。我不了解您分享的所有代码。它应该检测新的无线网络。它需要用户登录到网络?它在后台与应用程序一起工作? –

+0

否则,如果(状态== ReachableViaWWAN) {// 2G,3G,4G } ...在这里,你可以检测网络。这项工作,如果在后台模式以及每当你需要检查连接,如果([kAppDelegateObject checkInternetConnection]){} –

+0

(status == ReachableViaWWAN) { // 3G,2G –