美文网首页
iOS PushKit调试小记

iOS PushKit调试小记

作者: 达若漠沙 | 来源:发表于2018-09-18 19:31 被阅读163次

    1、在appdelegate中引入PushKit 并遵循PKPushRegistryDelegate协议

    #import <PushKit/PushKit.h>
    

    2、设置通知样式

         UIApplication *application = [UIApplication sharedApplication];
         UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
         UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
    [application registerUserNotificationSettings:settings]; 
    

    3、实现代理协议

    - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
    }
    
    - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
        }
    
    

    4、设置代理

        if ([UIDevice currentDevice].systemVersion.floatValue >= 8) {
            PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:nil];
            pushRegistry.delegate = self;
            pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
        }
    

    5、在target-->Capabilities-->打开Background Model 并勾选Remote notifications


    设置推送

    如果使用的是Xcode9创建的工程,需要在
    target--> Info -->Required background modes中添加
    App provides Voice over IP services
    6、登录开发者账号后台,生成一个voip的证书并安装在电脑上,此证书在开发环境下依然可以用。


    此证书在开发环境一样可以用

    Ok,配置完成,开始玩耍把。哦,千万记得把证书导出来给服务器的小伙伴,然后一起快乐玩耍把。

    相关文章

      网友评论

          本文标题:iOS PushKit调试小记

          本文链接:https://www.haomeiwen.com/subject/reemnftx.html