代码之家  ›  专栏  ›  技术社区  ›  jfalexvijay

设备未接收推送通知

  •  1
  • jfalexvijay  · 技术社区  · 14 年前

    我从下面的url获得了代码(PHP):

    http://code.google.com/p/apns-php/

    APNS.php文件

    date_default_timezone_set('Asia/Calcutta');
    require_once 'ApnsPHP/Autoload.php';
    $push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'ApnsPHP/apple_push_notification_production.pem'
    );
    
    $push->setRootCertificationAuthority('ApnsPHP/entrust_root_certification_authority.pem');
    $push->connect();
    $message = new ApnsPHP_Message('****');
    $message->setCustomIdentifier("Message-Badge-5");
    $message->setText('Hello APNs-enabled device!');
    $message->setBadge(5);
    $message->setSound('default');
    $message->setCustomProperty('acme2', array('bang', 'whiz'));
    $message->setExpiry(30);
    $push->add($message);
    $push->send();
    $push->disconnect();
    $aErrorQueue = $push->getErrors();
    if (!empty($aErrorQueue)) {
    var_dump($aErrorQueue);
    }

    目标C:

    -(void) applicationDidFinishLaunching:(UIApplication *)application{
        NSLog(@"Initiating push notification.");
        [[UIApplication sharedApplication] 
         registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }
    
    -(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
        NSLog(@"Device Token : %@", deviceToken);
        self.currentDeviceToken = [[[deviceToken description] 
                                                          stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@""]] 
                                                         stringByReplacingOccurrencesOfString:@" " withString:@""];;
        NSLog(@"Device Token : %@", self.currentDeviceToken);
        NSLog(@"Remote type : %d", [[UIApplication sharedApplication] enabledRemoteNotificationTypes]);
    }
    
    -(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
        NSLog(@"Error in registration : %@", error);
        self.currentDeviceToken = @"no device token";
    }
    
    -(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
        NSLog(@"Received Notification");
        NSLog(@"remote notification: %@",[userInfo description]);
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    
        NSString *alert = [apsInfo objectForKey:@"alert"];
        NSLog(@"Received Push Alert: %@", alert);
    
        NSString *sound = [apsInfo objectForKey:@"sound"];
        NSLog(@"Received Push Sound: %@", sound);
    
        NSString *badge = [apsInfo objectForKey:@"badge"];
        NSLog(@"Received Push Badge: %@", badge);
        application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
    }

    谢谢。

    1 回复  |  直到 14 年前
        1
  •  0
  •   jfalexvijay    14 年前

    我解决了这个问题。

    我已经为我的申请创建了entitlements.plist。现在一切正常。