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

     1. // 注册远程通知服务(第一次注册服务的时候会弹出提醒框,让用户授权)

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // 注册远程通知服务(第一次注册服务的时候会弹出提醒框,让用户授权)
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
        
      // 添加一个label,检查启动方式 UILabel
    *label = [[UILabel alloc] init]; label.backgroundColor = [UIColor lightGrayColor]; label.frame = CGRectMake(0, 100, 320, 300); label.font = [UIFont systemFontOfSize:15]; label.numberOfLines = 0; [self.window.rootViewController.view addSubview:label]; NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo) { label.text = [userInfo description]; } else { label.text = @"直接点击app图标启动的程序"; } return YES; }

    2.获取设备的deviceToken

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        NSLog(@"注册远程通知成功----%@", deviceToken);
        /**
         1.将deviceToken发送给公司的服务器
        c330833f 248c4fed e87068b6 c4b90ee8 a2b57119 aac2b93d 3f2eb27f e7d44c8c
        c330833f 248c4fed e87068b6 c4b90ee8 a2b57119 aac2b93d 3f2eb27f e7d44c8c
    
    }

    3.接收到远程推送通知时就会调用

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
      // 在这里读取远程通知的一些内容 NSLog(@"接收到远程通知--%@", userInfo[@"userInfo"]); }
  • 相关阅读:
    svn 相关
    Xcode 升级到7.2版本出现崩溃想象
    IOS UILabel用UITapGestureRecognizer实现点击事件
    JSon解析
    IOS StoryBoard下的视图跳转
    Http中的get和post的区别
    swift-delegate(代理)或者block传值
    swift-自定义TabBar工具栏
    利用POPAnimatableProperty属性来实现动画倒计时
    NSLayoutConstraints加动画来改变约束
  • 原文地址:https://www.cnblogs.com/shen5214444887/p/5188843.html
Copyright © 2011-2022 走看看