网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

ios8下LocationManager及Nsnotification使用

  1. location service使用

    专注于为中小企业提供成都做网站、成都网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业濮阳县免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了近千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

    ios8之前locationservice在应用开启

    self.locationManager = [[CLLocatonManager alloc] init]

    [self.locationManager startUpdatingLocation];

    在iOS8上需要加上kCLAuthorizationStatusAuthorizedAlways,在app中的info.plist中添加NSLocationAlwaysUsageDescription 或者 NSLocationWhenInUseUsageDescription其中一个key,value的值可以任意填写,会在请求获取位置的对话框中显示

    请求获取位置权限

        // 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];

          }

        实现代理方法,当获取到这个权限时

 - (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设置获取通知的权限和之前有所不同

#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{

   

}

设置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

}


分享名称:ios8下LocationManager及Nsnotification使用
文章链接:http://bjjierui.cn/article/gciddi.html

其他资讯