APNS Apple推送服务通知未收到

时间:2015-08-20 13:27:22

标签: php ios objective-c

我已经使用了APNS Apple推送服务通知的代码消息是从我的服务器发送的,但它没有收到设备。请查看以下网址:

https://indiegirlworld.com/app/license_iphone/sample_push.php

以下是我从上述链接获得的消息:

  

Thu,2015年8月20日15:22:20 +0200 ApnsPHP [315874]:信息:尝试   ssl://gateway.sandbox.push.apple.com:2195 ...星期四,2015年8月20日15:22:21   +0200 ApnsPHP [315874]:信息:连接到ssl://gateway.sandbox.push.apple.com:2195。星期四,2015年8月20日15:22:21   +0200 ApnsPHP [315874]:INFO:发送消息队列,运行#1:1消息留在队列中。星期四,2015年8月20日15:22:21 +0200   ApnsPHP [315874]:状态:发送消息ID 1 [自定义标识符:   Message-Badge-3](1/3):154字节。星期四,2015年8月20日15:22:21 +0200   ApnsPHP [315874]:信息:已断开连接。

1 个答案:

答案 0 :(得分:0)

您是否检查过Push通知设置为“ON”的设置?

另一件事推送通知只能在真实设备中接收而不是在模拟器中。

您可以从模拟器发送推送通知(因为它只是一个Web服务调用。)。

- 更新 -

以下代码请求通知。

在appDelegate.m中写(didFinishLaunchingWithOptions:)

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        NSLog(@"Requesting permission for push notifications..."); // iOS 8
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound categories:nil];
        [UIApplication.sharedApplication registerUserNotificationSettings:settings];
    }
    else {
        NSLog(@"Registering device for push notifications..."); // iOS 7 and earlier
        [UIApplication.sharedApplication registerForRemoteNotificationTypes: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }

更新appDelegate.m

中的以下方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Store DeviceToken some way like in NSUserDefault (if needed to pass device token)
    // Write alert for success to register for push
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { 
    // Write alert for failed to register for push
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    // Write alert code that shows you have successfully received alert
    // after that maintain your push
}
相关问题