Ios DidReceiveDemotonification不起作用9

Ios DidReceiveDemotonification不起作用9,ios,apple-push-notifications,Ios,Apple Push Notifications,我按照以下步骤进行推送通知,但无法在设备上接收推送 步骤 在我的项目中创建和添加推送应用id和配置文件 在我的项目中启用推送通知 制作p12文件nd.pem文件 将.pem文件发送给php开发人员 在我的应用程序delegate.m中使用以下代码 守则: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Over

我按照以下步骤进行推送通知,但无法在设备上接收推送

步骤

  • 在我的项目中创建和添加推送应用id和配置文件
  • 在我的项目中启用推送通知
  • 制作p12文件nd.pem文件
  • 将.pem文件发送给php开发人员
  • 在我的应用程序delegate.m中使用以下代码
  • 守则:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        //ios 9
        UIUserNotificationType types = UIUserNotificationTypeBadge |
        UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    
        UIUserNotificationSettings *mySettings =
        [UIUserNotificationSettings settingsForTypes:types categories:nil];
    
        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    
    
        return YES;
    }
    
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
        if (notificationSettings.types != UIUserNotificationTypeNone) {
            NSLog(@"didRegisterUser");
            [application registerForRemoteNotifications];
        }
    }
    
    - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken 
    {
        NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
        token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    
        Globals *globlClass = [Globals sharedInstance];
        globlClass.DeviceToken = [NSString stringWithFormat:@"%@",token];
    
        NSLog(@"\n\n\n\n\n device token===%@\n\n\n\n",globlClass.DeviceToken);
    }
    
    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
        NSLog(@"failed to regiser %@", err);
    }
    
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
    {
        NSLog(@"notification options %@", userInfo);
    
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Super" message:@"welcome" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    
        for (id key in userInfo) {
            NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
            UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    
            UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
            [myTextField setBackgroundColor:[UIColor whiteColor]];
            myTextField.text = [userInfo objectForKey:key];
            [myAlertView addSubview:myTextField];
            [myAlertView show];
        }    
    
    }
    
    -(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
    //应用程序启动后自定义的覆盖点。
    //ios 9
    UIUserNotificationType类型=UIUserNotificationTypeBadge|
    UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings*mySettings=
    [UIUserNotificationSettings设置类型:类型类别:nil];
    [[UIApplication sharedApplication]注册表通知设置:mySettings];
    返回YES;
    }
    -(void)应用程序:(UIApplication*)应用程序didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings{
    if(notificationSettings.types!=UIUserNotificationTypeNone){
    NSLog(@“didRegisterUser”);
    [申请登记处证明];
    }
    }
    -(无效)应用程序:(UIApplication*)应用程序DIdRegisterForRemotionTificationswithDeviceToken:(NSData*)devToken
    {
    NSString*标记=[[devToken description]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@”“];
    token=[token StringByReplacingOfString:@“with String:@]”的发生率;
    Globals*GlobalClass=[Globals sharedInstance];
    globlClass.DeviceToken=[NSString stringWithFormat:@“%@”,标记];
    NSLog(@“\n\n\n\n设备令牌===%@\n\n\n\n”,globlClass.DeviceToken);
    }
    -(无效)应用程序:(UIApplication*)应用程序未能注册远程通知错误:(N错误*)错误{
    NSLog(@“未能注册%@”,错误);
    }
    -(无效)应用程序:(UIApplication*)应用程序DidReceiveMemotentification:(NSDictionary*)用户信息
    {
    NSLog(@“通知选项%@”,userInfo);
    UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“超级”消息:@“欢迎”代表:自我取消按钮:@“确定”其他按钮:无];
    [警报显示];
    for(userInfo中的id键){
    NSLog(@“key:%@,value:%@”,key[userInfo objectForKey:key]);
    UIAlertView*myAlertView=[[UIAlertView alloc]initWithTitle:@“您的标题在这里!”消息:@“此已覆盖”代理:自取消按钮:@“取消”其他按钮:@“确定”,无];
    UITextField*myTextField=[[UITextField alloc]initWithFrame:CGRectMake(12.0,45.0,260.0,25.0)];
    [myTextField setBackgroundColor:[UIColor whiteColor]];
    myTextField.text=[userInfo objectForKey:key];
    [myAlertView addSubview:myTextField];
    [myAlertView show];
    }    
    }
    
    注册用户通知设置后,您需要通过调用此方法注册远程通知

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        //ios 9
        UIUserNotificationType types = UIUserNotificationTypeBadge |
        UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    
        UIUserNotificationSettings *mySettings =
        [UIUserNotificationSettings settingsForTypes:types categories:nil];
    
        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    
       //call this method here
       [[UIApplication sharedApplication] registerForRemoteNotifications];
    
        return YES; 
    }
    

    注册用户通知设置后,您需要通过调用此方法注册远程通知

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        //ios 9
        UIUserNotificationType types = UIUserNotificationTypeBadge |
        UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    
        UIUserNotificationSettings *mySettings =
        [UIUserNotificationSettings settingsForTypes:types categories:nil];
    
        [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    
       //call this method here
       [[UIApplication sharedApplication] registerForRemoteNotifications];
    
        return YES; 
    }
    

    在AppDelegate.m中的didFinishLaunchingWithOptions中添加以下代码:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
    

    在iOS 9.0和Xcode 7.2上为我工作。

    在您的didFinishLaunchingWithOptions中添加以下代码,在AppDelegate.m中:

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
    

    为我在iOS 9.0和Xcode 7.2上工作。

    一步一步地执行此操作。您确定服务器端代码正确吗?是否调用了didRegisterUserNotificationSettings?您是否已获取令牌并将其发送到服务器?请注意开发和分发。@Ani Khechoya是的,我已获取令牌并将其发送到服务器。那么问题可能出在您的.pem文件上。你是怎么做的?您的个人资料是否用于开发?请按此步骤进行操作您确定服务器端代码正确吗?是否调用了didRegisterUserNotificationSettings?您是否已获取令牌并将其发送到服务器?请注意开发和分发。@Ani Khechoya是的,我已获取令牌并将其发送到服务器。那么问题可能出在您的.pem文件上。你是怎么做的?您的个人资料是否用于发展?