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"]); }
原文地址:https://www.cnblogs.com/shen5214444887/p/5188843.html