中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

ios8下LocationManager及Nsnotification使用

發布時間:2020-06-10 19:58:40 來源:網絡 閱讀:855 作者:Demidroid 欄目:移動開發
  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;

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];

    }

    else{

        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];

        [application registerUserNotificationSettings:notificationSettings];

        [application registerForRemoteNotifications];

    }

    

#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 = [UIApplication sharedApplication];

    

#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 ([self checkNotificationType: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

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乌鲁木齐市| 信丰县| 沈阳市| 年辖:市辖区| 天门市| 宁河县| 永州市| 延吉市| 拜城县| 长泰县| 兴宁市| 门头沟区| 广汉市| 甘谷县| 房山区| 任丘市| 绩溪县| 凭祥市| 措美县| 花莲市| 关岭| 黄骅市| 岚皋县| 涞源县| 永定县| 临漳县| 灯塔市| 乐昌市| 胶州市| 华安县| 汉源县| 吉林省| 新蔡县| 平乡县| 海阳市| 醴陵市| 新晃| 沽源县| 九寨沟县| 蕲春县| 富锦市|