iOS开发检测是否开启定位、是否允许消息推送等权限的实例

1.iOS开发检测是否开启定位:

需要导入:

#import <CoreLocation/CoreLocation.h> 

代码如下:

+ (void)openLocationServiceWithBlock:(ReturnBlock)returnBlock
{
  BOOL isOPen = NO;
  if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {
    isOPen = YES;
  }
  if (returnBlock) {
    returnBlock(isOpen);
  }
} 

2.iOS开发检测是否允许消息推送:

需要导入:

#import <UserNotifications/UserNotifications.h> 

代码如下:

+ (void)openMessageNotificationServiceWithBlock:(ReturnBlock)returnBlock
{
 BOOL isOpen = NO;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
 UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
 if (setting.types != UIUserNotificationTypeNone) {
  isOpen = YES;
 }
#else
 UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
 if (type != UIRemoteNotificationTypeNone) {
  isOpen = YES;
 }
#endif
 if (returnBlock) {
  returnBlock(isOpen);
 }
} 
+ (void)openMessageNotificationServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
 [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
  if (returnBlock) {
   returnBlock(settings.authorizationStatus == UNAuthorizationStatusAuthorized);
  }
 }];
#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
 returnBlock([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]);
#else
 UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
 if (returnBlock) {
  returnBlock(type != UIRemoteNotificationTypeNone);
 }
#endif
} 

3.iOS开发检测是否开启摄像头:

需要导入:

#import <AVFoundation/AVFoundation.h> 

代码如下:

+ (void)openCaptureDeviceServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
  AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  if (authStatus == AVAuthorizationStatusNotDetermined) {
    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
      if (returnBlock) {
        returnBlock(granted);
      }
    }];
    return NO;
  } else if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
    returnBlock(NO);
  } else {
    returnBlock(YES);
  }
#endif
}

4.iOS开发检测是否开启相册:

需要导入:

#import <Photos/Photos.h>#import <AssetsLibrary/AssetsLibrary.h> 

代码如下:

+ (void)openAlbumServiceWithBlock:(ReturnBlock)returnBlock
{
  BOOL isOpen;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
  PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
  isOpen = YES;
  if (authStatus == PHAuthorizationStatusRestricted || authStatus == PHAuthorizationStatusDenied) {
    isOpen = NO;
  }
#else
  ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
  isOpen = YES;
  if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {
    isOpen = NO;
  }
#endif
  if (returnBlock) {
    returnBlock(isOpen);
  }
}

5.iOS开发检测是否开启麦克风:

需要导入:

#import <AVFoundation/AVFoundation.h> 

代码如下:

+ (void)openRecordServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
  AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];
  if (permissionStatus == AVAudioSessionRecordPermissionUndetermined) {
    [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
      if (returnBlock) {
        returnBlock(granted);
      }
    }];
  } else if (permissionStatus == AVAudioSessionRecordPermissionDenied) {
    returnBlock(NO);
  } else {
    returnBlock(YES);
  }
#endif
}

6.iOS开发检测是否开启通讯录:

需要导入:

#import <AddressBook/AddressBook.h>#import <Contacts/Contacts.h> 

代码如下:

+ (void)openContactsServiceWithBolck:(ReturnBlock)returnBolck
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
 CNAuthorizationStatus cnAuthStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
 if (cnAuthStatus == CNAuthorizationStatusNotDetermined) {
  CNContactStore *store = [[CNContactStore alloc] init];
  [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) {
   if (returnBolck) {
    returnBolck(granted);
   }
  }];
 } else if (cnAuthStatus == CNAuthorizationStatusRestricted || cnAuthStatus == CNAuthorizationStatusDenied) {
  if (returnBolck) {
   returnBolck(NO);
  }
 } else {
  if (returnBolck) {
   returnBolck(YES);
  }
 }
#else
 //ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
 ABAddressBookRef addressBook = ABAddressBookCreate();
 ABAuthorizationStatus authStatus = ABAddressBookGetAuthorizationStatus();
 if (authStatus != kABAuthorizationStatusAuthorized) {
  ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
   dispatch_async(dispatch_get_main_queue(), ^{
    if (error) {
     NSLog(@"Error: %@", (__bridge NSError *)error);
     if (returnBolck) {
      returnBolck(NO);
     }
    } else {
     if (returnBolck) {
      returnBolck(YES);
     }
    }
   });
  });
 } else {
  if (returnBolck) {
   returnBolck(YES);
  }
 }
#endif
}

7.iOS开发检测是否开启蓝牙:

需要导入:

#import <CoreBluetooth/CoreBluetooth.h> 

代码如下:

+ (void)openPeripheralServiceWithBolck:(ReturnBlock)returnBolck
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
  CBPeripheralManagerAuthorizationStatus cbAuthStatus = [CBPeripheralManager authorizationStatus];
  if (cbAuthStatus == CBPeripheralManagerAuthorizationStatusNotDetermined) {
    if (returnBolck) {
      returnBolck(NO);
    }
  } else if (cbAuthStatus == CBPeripheralManagerAuthorizationStatusRestricted || cbAuthStatus == CBPeripheralManagerAuthorizationStatusDenied) {
    if (returnBolck) {
      returnBolck(NO);
    }
  } else {
    if (returnBolck) {
      returnBolck(YES);
    }
  }
#endif
}

8.iOS开发检测是否开启日历/备忘录:

需要导入:

#import <EventKit/EventKit.h> 

代码如下:

+ (void)openEventServiceWithBolck:(ReturnBlock)returnBolck withType:(EKEntityType)entityType
{
  // EKEntityTypeEvent  代表日历
  // EKEntityTypeReminder 代表备忘
  EKAuthorizationStatus ekAuthStatus = [EKEventStore authorizationStatusForEntityType:entityType];
  if (ekAuthStatus == EKAuthorizationStatusNotDetermined) {
    EKEventStore *store = [[EKEventStore alloc] init];
    [store requestAccessToEntityType:entityType completion:^(BOOL granted, NSError *error) {
      if (returnBolck) {
        returnBolck(granted);
      }
    }];
  } else if (ekAuthStatus == EKAuthorizationStatusRestricted || ekAuthStatus == EKAuthorizationStatusDenied) {
    if (returnBolck) {
      returnBolck(NO);
    }
  } else {
    if (returnBolck) {
      returnBolck(YES);
    }
  }
}

9.iOS开发检测是否开启联网:

需要导入:

#import <CoreTelephony/CTCellularData.h> 

代码如下:

+ (void)openEventServiceWithBolck:(ReturnBlock)returnBolck
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
  CTCellularData *cellularData = [[CTCellularData alloc] init];
  cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state){
    if (state == kCTCellularDataRestrictedStateUnknown || state == kCTCellularDataNotRestricted) {
      if (returnBolck) {
        returnBolck(NO);
      }
    } else {
      if (returnBolck) {
        returnBolck(YES);
      }
    }
  };
  CTCellularDataRestrictedState state = cellularData.restrictedState;
  if (state == kCTCellularDataRestrictedStateUnknown || state == kCTCellularDataNotRestricted) {
    if (returnBolck) {
      returnBolck(NO);
    }
  } else {
    if (returnBolck) {
      returnBolck(YES);
    }
  }
#endif
}

10.iOS开发检测是否开启健康:

需要导入:

#import <HealthKit/HealthKit.h> 

代码如下:

+ (void)openHealthServiceWithBolck:(ReturnBlock)returnBolck
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
 if (![HKHealthStore isHealthDataAvailable]) {
  if (returnBolck) {
   returnBolck(NO);
  }
 } else {
  HKHealthStore *healthStore = [[HKHealthStore alloc] init];
  HKObjectType *hkObjectType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
  HKAuthorizationStatus hkAuthStatus = [healthStore authorizationStatusForType:hkObjectType];
  if (hkAuthStatus == HKAuthorizationStatusNotDetermined) {
   // 1. 你创建了一个NSSet对象,里面存有本篇教程中你将需要用到的从Health Stroe中读取的所有的类型:个人特征(血液类型、性别、出生日期)、数据采样信息(身体质量、身高)以及锻炼与健身的信息。
   NSSet <HKObjectType *> * healthKitTypesToRead = [[NSSet alloc] initWithArray:@[[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth],[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBloodType],[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBiologicalSex],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight],[HKObjectType workoutType]]];
   // 2. 你创建了另一个NSSet对象,里面有你需要向Store写入的信息的所有类型(锻炼与健身的信息、BMI、能量消耗、运动距离)
   NSSet <HKSampleType *> * healthKitTypesToWrite = [[NSSet alloc] initWithArray:@[[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning],[HKObjectType workoutType]]];
   [healthStore requestAuthorizationToShareTypes:healthKitTypesToWrite readTypes:healthKitTypesToRead completion:^(BOOL success, NSError *error) {
    if (returnBolck) {
     returnBolck(success);
    }
   }];
  } else if (hkAuthStatus == HKAuthorizationStatusSharingDenied) {
   if (returnBolck) {
    returnBolck(NO);
   }
  } else {
   if (returnBolck) {
    returnBolck(YES);
   }
  }
 }
#endif
}

11.iOS开发检测是否开启Touch ID:

需要导入:

#import <LocalAuthentication/LocalAuthentication.h>

代码如下:

#pragma mark - 开启Touch ID服务
+ (void)openTouchIDServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
 LAContext *laContext = [[LAContext alloc] init];
 laContext.localizedFallbackTitle = @"输入密码";
 NSError *error;
 if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
  NSLog(@"恭喜,Touch ID可以使用!");
  [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"需要验证您的指纹来确认您的身份信息" reply:^(BOOL success, NSError *error) {
   if (success) {
    // 识别成功
    if (returnBlock) {
     [[NSOperationQueue mainQueue] addOperationWithBlock:^{
      returnBlock(YES);
     }];
    }
   } else if (error) {
    if (returnBlock) {
     [[NSOperationQueue mainQueue] addOperationWithBlock:^{
      returnBlock(NO);
     }];
    }
    if (error.code == LAErrorAuthenticationFailed) {
     // 验证失败
    }
    if (error.code == LAErrorUserCancel) {
     // 用户取消
    }
    if (error.code == LAErrorUserFallback) {
     // 用户选择输入密码
    }
    if (error.code == LAErrorSystemCancel) {
     // 系统取消
    }
    if (error.code == LAErrorPasscodeNotSet) {
     // 密码没有设置
    }
   }
  }];
 } else {
  NSLog(@"设备不支持Touch ID功能,原因:%@",error);
  if (returnBlock) {
   returnBlock(NO);
  }
 }
#endif
}

12.iOS开发检测是否开启Apple Pay:

需要导入:

#import <PassKit/PassKit.h> 

代码如下:

#pragma mark - 开启Apple Pay服务
+ (void)openApplePayServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
  NSArray<PKPaymentNetwork> *supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkDiscover];
  if ([PKPaymentAuthorizationViewController canMakePayments] && [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:supportedNetworks]) {
    if (returnBlock) {
      returnBlock(YES);
    }
  } else {
    if (returnBlock) {
      returnBlock(NO);
    }
  }
#endif
}

13.iOS开发检测是否开启语音识别:

需要导入:

#import <Speech/Speech.h> 

代码如下:

#pragma mark - 开启语音识别服务
+ (void)openSpeechServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
 SFSpeechRecognizerAuthorizationStatus speechAuthStatus = [SFSpeechRecognizer authorizationStatus];
 if (speechAuthStatus == SFSpeechRecognizerAuthorizationStatusNotDetermined) {
  [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
   if (status == SFSpeechRecognizerAuthorizationStatusAuthorized) {
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(YES);
     }
    });
   } else {
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(YES);
     }
    });
   }
  }];
 } else if (speechAuthStatus == SFSpeechRecognizerAuthorizationStatusAuthorized) {
  if (returnBlock) {
   returnBlock(YES);
  }
 } else{
  if (returnBlock) {
   returnBlock(NO);
  }
 }
#endif
}

14.iOS开发检测是否开启媒体资料库/Apple Music:

需要导入:

#import <MediaPlayer/MediaPlayer.h> 

代码如下:

#pragma mark - 开启媒体资料库/Apple Music 服务
+ (void)openMediaPlayerServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_3
 MPMediaLibraryAuthorizationStatus authStatus = [MPMediaLibrary authorizationStatus];
 if (authStatus == MPMediaLibraryAuthorizationStatusNotDetermined) {
  [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status) {
   if (status == MPMediaLibraryAuthorizationStatusAuthorized) {
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(YES);
     }
    });
   }else{
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(NO);
     }
    });
   }
  }];
 }else if (authStatus == MPMediaLibraryAuthorizationStatusAuthorized){
  if (returnBlock) {
   returnBlock(YES);
  }
 }else{
  if (returnBlock) {
   returnBlock(NO);
  }
 }
#endif
}

15.iOS开发检测是否开启Siri:

需要导入:

#import <Intents/Intents.h> 

代码如下:

#pragma mark - 开启Siri服务
+ (void)openSiriServiceWithBlock:(ReturnBlock)returnBlock
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
 INSiriAuthorizationStatus siriAutoStatus = [INPreferences siriAuthorizationStatus];
 if (siriAutoStatus == INSiriAuthorizationStatusNotDetermined) {
  [INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {
   if (status == INSiriAuthorizationStatusAuthorized) {
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(YES);
     }
    });
   } else {
    dispatch_async(dispatch_get_main_queue(), ^{
     if (returnBlock) {
      returnBlock(YES);
     }
    });
   }
  }];
 } else if (siriAutoStatus == INSiriAuthorizationStatusAuthorized) {
  if (returnBlock) {
   returnBlock(YES);
  }
 } else{
  if (returnBlock) {
   returnBlock(NO);
  }
 }
#endif
}

在.h文件中申明block

#if NS_BLOCKS_AVAILABLE
typedef void(^ReturnBlock)(BOOL isOpen);
#endif 

由于iOS10的权限原因,需要在工程的info.plist(右击选择Open as - Source Code)中添加

<!-- 相册 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<!-- 相机 -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<!-- 麦克风 -->
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<!-- 位置 -->
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<!-- 在使用期间访问位置 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<!-- 始终访问位置 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<!-- 日历 -->
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<!-- 提醒事项 -->
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<!-- 运动与健身 -->
<key>NSMotionUsageDescription</key>
 <string>App需要您的同意,才能访问运动与健身</string>
<!-- 健康更新 -->
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<!-- 健康分享 -->
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<!-- 蓝牙 -->
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<!-- 媒体资料库 -->
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<!-- 语音识别 -->
<key>NSSpeechRecognitionUsageDescription</key>
<string>App需要您的同意,才能使用语音识别</string>

以上这篇iOS开发检测是否开启定位、是否允许消息推送等权限的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

您可能感兴趣的文章:

  • 讲解iOS开发中基本的定位功能实现
  • iOS消息远程推送通知
  • iOS10实现推送功能时的注意点和问题总结
(0)

相关推荐

  • iOS10实现推送功能时的注意点和问题总结

    1.在项目 target 中,打开Capabilitie -> Push Notifications,并会自动在项目中生成 .entitlement 文件.(很多同学升级后,获取不到 deviceToken,大概率是由于没开这个选项) Capabilitie -> Push Notifications 自动生成 .entitlement 2.确保添加了 UserNotifications.framework,并 import到 AppDelegate,记得实现 UNUserNotificati

  • iOS消息远程推送通知

    本文实例为大家分享了iOS消息推送.iOS远程通知代码,供大家参考,具体内容如下 消息推送 /* 要开发测试消息机制的程序,必须用真机测试 推送消息的类型 UIRemoteNotificationTypeNone 不接收推送消息 UIRemoteNotificationTypeBadge 接收图标数字 UIRemoteNotificationTypeSound 接收音频 UIRemoteNotificationTypeAlert 接收消息文字 UIRemoteNotificationTypeNe

  • 讲解iOS开发中基本的定位功能实现

    一.简单说明 1.CLLocationManager   CLLocationManager的常用操作和属性   开始用户定位- (void)startUpdatingLocation;   停止用户定位- (void) stopUpdatingLocation;   说明:当调用了startUpdatingLocation方法后,就开始不断地定位用户的位置,中途会频繁地调用代理的下面方法 复制代码 代码如下: - (void)locationManager:(CLLocationManager

  • iOS开发检测是否开启定位、是否允许消息推送等权限的实例

    1.iOS开发检测是否开启定位: 需要导入: #import <CoreLocation/CoreLocation.h> 代码如下: + (void)openLocationServiceWithBlock:(ReturnBlock)returnBlock { BOOL isOPen = NO; if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] !

  • SpringBoot整合WxJava开启消息推送的实现

    目录 1.引入 WxJava 依赖 2.申请微信小程序 3.微信小程序配置信息 4.消息推送配置 5.接收消息推送的 API 6.消息推送测试 接入微信小程序消息推送服务,可以3种方式选择其一: 1.开发者服务器接收消息推送2.云函数接收消息推送3.微信云托管服务接收消息推送 开发者服务器接收消息推送,开发者需要按照如下步骤完成: 1.填写服务器配置2.验证服务器地址的有效性3.据接口文档实现业务逻辑,接收消息和事件 1.引入 WxJava 依赖 <!-- web支持 --> <depe

  • 详解IOS开发之实现App消息推送(最新)

    好久没有写过博客啦,今天就由本菜鸟给大家做一个简单的IOSApp消息推送教程吧!一切从0开始,包括XCode6, IOS8, 以及苹果开发者中心最新如何注册应用,申请证书以及下载配置概要文件,相信很多刚开始接触iOS的人会很想了解一下.(ps:网上看了一下虽然有很多讲述推送的好教程,我也是看着一步步学会的,但是这些教程的时间都是去年或者更早时期的,对引导新手来说不是很合适) 第一部分 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps:其实每一篇教程都有),先来看一张苹果官方对其推送做出

  • iOS Remote Notification远程消息推送处理

    远程消息推送处理场景有三种:分别是app还没有运行.app在前台运行以及app在后台运行,下面介绍相关流程及三种场景下处理步骤 1.流程 (1)注册通知 首先是在注册远程消息推送,需要注意的是iOS8及以后的系统中注册方法有所改变(同时证书设置以及push权限也需要开启).这一步的目的是,允许app接收远程消息推送. (2)绑定deviceToken deviceToken相当于设备的一个标识,服务器根据这个标识来进行消息推送. ①当用户同意app接收远程消息推送后,手机会向APNs发起一个请求

  • iOS消息推送原理及具体实现代码

    一.消息推送原理 在实现消息推送之前先提及几个于推送相关概念,如下图1-1: 1.Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服务端[消息的发起者]): 2.APNS:Apple Push Notification Service[苹果消息推送服务器]: 3.iPhone:用来接收APNS下发下来的消息: 4.Client App:IOS设备上的应用程序,用来接收iphone传递APNS下发的消息到制定

  • 轻松搞定iOS远程消息推送

    一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://www.jb51.net/article/93602.htm这篇博客中有详细的介绍,这里主要讨论远程推送的流程与配置过程. 二.远程推送机制的原理 1.从一张很火的图说起 搜索IOS远程推送,你总能看到一张如下的流程示意图,因为这张图确实很火,所以我也将它引用在此: 这张图示意的很清晰,大致意思是这样:你的应用服务端将消息发送到apple的APNS服务器,APNS服务器将消息推送到指定的Iphone,最后由

  • iOS实现消息推送及原理分析

    一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图1-1: 1.Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Provider可以理解为服务端[消息的发起者]): 2.APNS:Apple Push Notification Service[苹果消息推送服务器]: 3.iPhone:用来接收APNS下发下来的消息: 4.Client App:IOS设备上的应用程序,用来接收iphone传递APNS下发的消息到制

  • 微信开发 消息推送实现代码

    最近做微信公共号的开发,有个需求是这样的消息推送,以文本的形式把编辑的消息发送给微信企业号中的某一个应用组,这里做下笔记,以下是整理内容: //定义数据模型 public class Access_token { public Access_token() { // // TODO: 在此处添加构造函数逻辑 // } string _access_token; string _expires_in; /// /// 获取到的凭证 /// public string access_token {

  • iOS开发系列--地图与定位源代码详解

    概览 现在很多社交.电商.团购应用都引入了地图和定位功能,似乎地图功能不再是地图应用和导航应用所特有的.的确,有了地图和定位功能确实让我们的生活更加丰富多彩,极大的改变了我们的生活方式.例如你到了一个陌生的地方想要查找附近的酒店.超市等就可以打开软件搜索周边;类似的,还有很多团购软件可以根据你所在的位置自动为你推荐某些商品.总之,目前地图和定位功能已经大量引入到应用开发中.今天就和大家一起看一下iOS如何进行地图和定位开发. 定位 地图 定位 要实现地图.导航功能,往往需要先熟悉定位功能,在iO

随机推荐