簡體   English   中英

定位服務關閉通知

[英]Location service Turn off Notification

我的使用CoreLocation應用程序已注冊后台位置更新

當用戶從設置中關閉位置服務時,我想顯示UILocalNotification

iOS 6.1.3及更低版本中關閉位置服務后,我的應用程序可以在后台運行代碼,因此我可以向用戶展示UILocalNotification

但是在iOS 7中,一旦我關閉位置服務,我的應用程序將無法在后台執行一行代碼。

即使在iOS 7中,我也注冊了后台應用刷新。

如果禁用了服務,則可以設置委托方法並顯示UILocalNotification:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;

每當用戶在設置中禁用/啟用位置服務時,就會調用此方法。 您也可以使用此方法來確定是否啟用了位置服務

[CLLocationManager locationServicesEnabled]

我沒有測試過,但也許您覺得它有用。

添加@屬性(非原子性,強性)可訪問性* internetReachable;

然后在AppDelegate.h文件中,

在didFinishedLaunching方法的AppDelegate.m文件中添加以下代碼行:

[[NSNotificationCenter defaultCenter] addObserver:自我選擇器:@selector(NetWorkCheangeNoti :)名稱:kReachabilityChangedNotification對象:無];

internetReachable = [[[ReachabilityreachabilityForInternetConnection]保留]; [internetReachable startNotifier];

在AppDelegate.m中實現該方法,如下所示:

-(void)NetWorkCheangeNoti:(Reachability *)info {NetworkStatus internetStatus = [internetReachable currentReachabilityStatus]; 開關(internetStatus){case NotReachable:{

        NSLog(@"The internet is down.");
    }
        break;

    case ReachableViaWiFi:
    {
        //NSLog(@"The internet is working via WIFI");
    }
        break;

    case ReachableViaWWAN:
    {
        //NSLog(@"The internet is working via WWAN!");
    }
        break;

    default:
        break;
}

}

嘗試這個..!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM