pushkit是苹果在iOS8以后引入的一种新的push类型。使用pushkit收到通知时不会弹出警报。
首先要申请证书:
在工程设置里面的Background Mode里面添加voip、backgroundfetch、remotenotifications的支持。
在工程里引入pushkit框架:
#import <PushKit/PushKit.h>
PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:nil];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type{
//获取token,这个token需要上传到服务器
NSData * data = credentials.token;
NSString *str = [NSString stringWithFormat:@"%@",credentials.token];
}
//收到pushkit的通知时会调用这个方法,但是不会有UI上的显示
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type{
}
有一个测试推送的工具可以模拟服务器发送通知:链接