zoukankan      html  css  js  c++  java
  • 远程推送

    推送需要真机调试

     

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

     

    @implementation AppDelegate

     

     

     

     

     

    //注册完毕 远程推送通知之后就会调用

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

    {

        NSLog(@"%@",deviceToken);

    }

     

     

    //远程通知注册失败的时候就会调用

    -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

    {

        //常见失败的三种情况

        //1,BundliID没有用全称

        //2.描述文件没有在最后配置

        //3,AppleWWDRCA.cer 误删, 导致证书文件没有授权机构的签发

    }

     

    //接收到远程推送通知之后就会调用,前提,程序活着

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

    {

        NSLog(@"%@",userInfo);

    }

     

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Override point for customization after application launch.

        //注册通知,自动提示用户通知包含的类型

        UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];

        [[UIApplication sharedApplication]registerUserNotificationSettings:setting];

        //注册远程推送通知 这种方法会打包 uuid appid 生成devicetoken

        [[UIApplication sharedApplication]registerForRemoteNotifications];

        

        

        //取出通知内容

        if(launchOptions[UIApplicationLaunchOptionsLocalNotificationKey])

        {

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 300)];

            label.numberOfLines = 0;

            label.backgroundColor = [UIColor redColor];

            label.text= [NSString stringWithFormat:@"%@",launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];

            [self.window.rootViewController.view addSubview:label];

        }

        

        

        return YES;

    }

  • 相关阅读:
    MGR集群中节点间数据一致性如何检查?
    MySQL错误日志出现 [Note] InnoDB: Discarding tablespace of table db.table: Data structure corruption产生可能的原因及解决办法?
    Redis中如何发现并优化生产环境的big key?
    HashHelper
    设计模式-结构型-组合模式
    设计模式-结构型-享元模式
    设计模式-结构型-外观模式
    泛型Generic
    Redis之缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级
    设计模式-结构型-装饰者模式
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4655852.html
Copyright © 2011-2022 走看看