mirror of
https://github.com/openharmony/base_location.git
synced 2026-08-24 22:31:51 -04:00
!177 getLastLocation返回值添加判空逻辑
Merge pull request !177 from ruan-shaofei/master
This commit is contained in:
@@ -121,6 +121,9 @@ std::string CountryCodeManager::GetCountryCodeByLastLocation()
|
||||
std::shared_ptr<ReportManager> reportManager = DelayedSingleton<ReportManager>::GetInstance();
|
||||
if (reportManager) {
|
||||
auto lastLocation = reportManager->GetLastLocation();
|
||||
if (lastLocation == nullptr) {
|
||||
return code;
|
||||
}
|
||||
auto location = std::make_unique<Location>(*lastLocation);
|
||||
code = GetCountryCodeByLocation(location);
|
||||
lastCountryByLocation_->SetCountryCodeStr(code);
|
||||
@@ -262,14 +265,12 @@ bool CountryCodeManager::SubscribeLocaleConfigEvent()
|
||||
{
|
||||
auto eventCallback = [](const char *key, const char *value, void *context) {
|
||||
LBSLOGD(COUNTRY_CODE, "LOCALE_KEY changed");
|
||||
if (key && value && context) {
|
||||
auto manager = DelayedSingleton<CountryCodeManager>::GetInstance();
|
||||
if (manager == nullptr) {
|
||||
LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr");
|
||||
return;
|
||||
}
|
||||
manager->GetIsoCountryCode();
|
||||
auto manager = DelayedSingleton<CountryCodeManager>::GetInstance();
|
||||
if (manager == nullptr) {
|
||||
LBSLOGE(COUNTRY_CODE, "SubscribeLocaleConfigEvent CountryCodeManager is nullptr");
|
||||
return;
|
||||
}
|
||||
manager->GetIsoCountryCode();
|
||||
};
|
||||
|
||||
int ret = WatchParameter(LOCALE_KEY.c_str(), eventCallback, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user