location service使用
專注于為中小企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)濮陽縣免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
ios8之前l(fā)ocationservice在應(yīng)用開啟
self.locationManager = [[CLLocatonManager alloc] init]
[self.locationManager startUpdatingLocation];
在iOS8上需要加上kCLAuthorizationStatusAuthorizedAlways,在app中的info.plist中添加NSLocationAlwaysUsageDescription 或者 NSLocationWhenInUseUsageDescription其中一個(gè)key,value的值可以任意填寫,會(huì)在請(qǐng)求獲取位置的對(duì)話框中顯示
請(qǐng)求獲取位置權(quán)限
// iOS 8 - request location services via requestWhenInUseAuthorization.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
} else {
// iOS 7 - We can't use requestWhenInUseAuthorization -- we'll get an unknown selector crash!
// Instead, you just start updating location, and the OS will take care of prompting the user
// for permissions.
[self.locationManager startUpdatingLocation];
}
實(shí)現(xiàn)代理方法,當(dāng)獲取到這個(gè)權(quán)限時(shí)
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
// We only need to start updating location for iOS 8 -- iOS 7 users should have already
// started getting location updates
if (status == kCLAuthorizationStatusAuthorizedAlways ||
status == kCLAuthorizationStatusAuthorizedWhenInUse) {
[manager startUpdatingLocation];
}
}
2.ios8設(shè)置獲取通知的權(quán)限和之前有所不同
#ifdef __IPHONE_8_0
if(SYSTEM_VERSION_LESS_THAN(@"8.0")){
UIRemoteNotificationType myTypes =UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeAlert |UIRemoteNotificationTypeSound;
[[UIApplicationsharedApplication]registerForRemoteNotificationTypes:myTypes];
}
else{
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeBadge |UIUserNotificationTypeSoundcategories:nil];
[application registerUserNotificationSettings:notificationSettings];
[applicationregisterForRemoteNotifications];
}
#else
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif
獲取remotenotification
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"remote notifation %@",userInfo);
}
//獲取到推送的通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
}
設(shè)置setbadgeNumber
- (void)setApplicationBadgeNumber:(NSInteger)badgeNumber
{
UIApplication *application = [UIApplicationsharedApplication];
#ifdef __IPHONE_8_0
// compile with Xcode 6 or higher (iOS SDK >= 8.0)
if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
{
application.applicationIconBadgeNumber = badgeNumber;
}
else
{
if ([selfcheckNotificationType:UIUserNotificationTypeBadge])
{
NSLog(@"badge number changed to %d", badgeNumber);
application.applicationIconBadgeNumber = badgeNumber;
}
else
NSLog(@"access denied for UIUserNotificationTypeBadge");
}
#else
// compile with Xcode 5 (iOS SDK < 8.0)
application.applicationIconBadgeNumber = badgeNumber;
#endif
}