2015-10-28 66 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 –