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;

    }

  • 相关阅读:
    关于Python Package下的Module import方式[转]
    go指针的一个小坑
    不错的python中级电子书
    virtualenv 安装及使用[转]
    Go语言的传参和传引用[转]
    gorename: easy refactoring tool for Golang[转]
    Python上下文管理器的使用
    Python使用DB-API操作MySQL数据库
    Python类的定义、方法和属性使用
    tomcat配置通过域名访问项目
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4655852.html
Copyright © 2011-2022 走看看