2014-09-04 48 views
0

根據請求的當前位置基於iOS的對話框(如下圖所示)的反饋推送視圖控制器的最佳做法是什麼?如何等待,直到當前位置對話框回答運行方法?

我試圖確定選擇後,要麼成功 - >發送用戶在流或失敗 - >顯示一個屏幕,要求他們允許當前位置。

據我已經收到來自哪裏按鈕按下分配CLLocationManager的方法調用此方法:

- (void) confirmInfo { 


    BOOL locationAllowed = [CLLocationManager locationServicesEnabled]; 

    if (locationAllowed==NO) { 
     // Show the how-to viewcontroller 
    } else { 
     // Go to the next step onboarding 
    } 

} 

但我不知道如何等待,直到輸入從對話框回來選擇哪個VC來顯示用戶。

enter image description here

回答

3

你可以委託方法的用戶將允許或即使用戶不使..並從響應你可以繼續你推彈出。

否則,你甚至可以嘗試基於塊結構來保持你的流量。 以下鏈接可以幫助你.. https://github.com/intuit/LocationManagerhttps://github.com/FuerteInternational/FTLocationManager

INTULocationManager *locMgr = [INTULocationManager sharedInstance]; 
[locMgr requestLocationWithDesiredAccuracy:INTULocationAccuracyCity 
            timeout:10.0 
         delayUntilAuthorized:YES // This parameter is optional, defaults to NO if omitted 
            block:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) { 
             if (status == INTULocationStatusSuccess) { 
              // Request succeeded, meaning achievedAccuracy is at least the requested accuracy, and 
              // currentLocation contains the device's current location. 
             } 
             else if (status == INTULocationStatusTimedOut) { 
              // Wasn't able to locate the user with the requested accuracy within the timeout interval. 
              // However, currentLocation contains the best location available (if any) as of right now, 
              // and achievedAccuracy has info on the accuracy/recency of the location in currentLocation. 
             } 
             else { 
              // An error occurred, more info is available by looking at the specific status returned. 
             } 
            }]; 
0

首先,創建一個CLLocationManager,然後設置你的控制器其委託,最後調用[self.locationManager startUpdatingLocations];顯示對話框。

然後使用CLLocationManagerDelegate方法來確定用戶選擇了什麼:

成功時,

– locationManager:didUpdateLocations:

被調用。否則

– locationManager:didFailWithError: