推送
<p>[TOC]</p>
<h2>前期准备</h2>
<ul>
<li>制作推送证书并在管理后台配置</li>
<li>客户端配置推送环境</li>
</ul>
<pre><code>[[QDClient sharedClient] updatePushScene:PUSHSCENE];
</code></pre>
<ul>
<li>客户端注册 APNS,并在获取到 APNS Token 时将值传给 SDK</li>
</ul>
<pre><code>- (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];
}
</code></pre>
<h2>属性设置</h2>
<p>SDK 提供全局 APNS 属性设置,用于设置免打扰时间。 <code>QDPushOptions</code></p>
<ul>
<li>获取推送设置</li>
</ul>
<pre><code>QDPushOptions *setting = [[QDClient sharedClient].apnsManager pushOptions];
</code></pre>
<ul>
<li>修改推送设置</li>
</ul>
<pre><code>[[QDClient sharedClient].apnsManager updateApnsSetting:setting completion:^(NSError * _Nullable error) {
}];
</code></pre>