zoukankan      html  css  js  c++  java
  • 【转】iOS8 推送 获取 devicetoken

    打开AppDelegate.m
    怎么做:
    首先:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    add Code like this
    #ifdef __IPHONE_8_0
      //Right, that is the point
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
    |UIRemoteNotificationTypeSound
    |UIRemoteNotificationTypeAlert) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    #else
        //register to receive notifications
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
    #endif

    接着:
    添加如下函数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #ifdef __IPHONE_8_0
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
    {
        //register to receive notifications
        [application registerForRemoteNotifications];
    }
     
    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
    {
        //handle the actions
        if ([identifier isEqualToString:@"declineAction"]){
        }
        else if ([identifier isEqualToString:@"answerAction"]){
        }
    }
    #endif

    然后你会在如下方法中获得deviceToken

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

    如果该函数没有响应, 使用如下函数并NSLog error

    1
    -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  • 相关阅读:
    jQuery 对象 等操作
    根据文件大小自动判断单位B,KB,MB,GB
    PHP 根据子ID递归获取父级ID,实现逐级分类导航效果
    JQuery 目录树jsTree插件用法
    关于循环列表中包含递归函数的问题
    PHP文件上传大小限制问题
    UEditor+七牛,实现图片直连上传
    修改Ueditor的图片上传地址
    Thinkphp3.2.3加载外部类并调用类里面的方法 获取token
    七牛云--开发笔记
  • 原文地址:https://www.cnblogs.com/A--G/p/4670964.html
Copyright © 2011-2022 走看看