推送

前期准备

  • 制作推送证书并在管理后台配置
  • 客户端配置推送环境
[[QDClient sharedClient] updatePushScene:PUSHSCENE];
  • 客户端注册 APNS,并在获取到 APNS Token 时将值传给 SDK
- (void)registerForRemoteNotification
{
    if (@available(iOS 11.0, *)) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (!granted)
            {
                dispatch_async_main_safe(^{
                    [[UIApplication sharedApplication].keyWindow makeToast:@"请开启推送功能否则无法收到推送通知" duration:2.0 position:CSToastPositionCenter];
                })
             }
        }];
     }
     else
     {
        UIUserNotificationType     types     = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
        categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
     }

    [[UIApplication sharedApplication] registerForRemoteNotifications];
}


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken {
    [[QDClient sharedClient] updateApnsToken:deviceToken];
}

属性设置

SDK 提供全局 APNS 属性设置,用于设置免打扰时间。 QDPushOptions

  • 获取推送设置
QDPushOptions *setting    = [[QDClient sharedClient].apnsManager pushOptions];
  • 修改推送设置
[[QDClient sharedClient].apnsManager updateApnsSetting:setting completion:^(NSError * _Nullable error) {

}];