简体   繁体   English

APNS Apple Push Service通知未收到

[英]APNS Apple Push Service Notification not recieving

I have used the code for APNS Apple Push Service Notification The message is sending from my server but it is not receiving to the device. 我已使用APNS Apple Push Service Notification的代码消息正在从服务器发送,但未接收到设备。 Check the URL below: 检查以下URL:

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

Below is the messages I have obtained from the above link: 以下是我从上述链接获得的消息:

Thu, 20 Aug 2015 15:22:20 +0200 ApnsPHP[315874]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195... Thu, 20 Aug 2015 15:22:21 +0200 ApnsPHP[315874]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195. 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。 Thu, 20 Aug 2015 15:22:21 +0200 ApnsPHP[315874]: INFO: Sending messages queue, run #1: 1 message(s) left in queue. 2015年8月20日,星期四15:22:21 +0200 ApnsPHP [315874]:信息:正在发送消息队列,运行#1:队列中还剩下1条消息。 Thu, 20 Aug 2015 15:22:21 +0200 ApnsPHP[315874]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-3] (1/3): 154 bytes. 2015年8月20日,星期四15:22:21 +0200 ApnsPHP [315874]:状态:正在发送消息ID 1 [自定义标识符:Message-Badge-3](1/3):154个字节。 Thu, 20 Aug 2015 15:22:21 +0200 ApnsPHP[315874]: INFO: Disconnected. 2015年8月20日,星期四,15:22:21 +0200 ApnsPHP [315874]:信息:已断开连接。

Did you checked in settings that Push notification are set to "ON"? 您是否签入了将推送通知设置为“开”的设置?

And another thing push notification can only received in Real devices not in Simulators. 另外,推送通知只能在Real设备中而不在Simulators中接收。

You can send push notification from simulator (Because it is just a web service call.). 您可以从模拟器发送推送通知(因为这只是一个Web服务调用。)。

-- UPDATE -- -更新-

The below code that requests for notifications. 以下请求通知的代码。

Write in appDelegate.m (didFinishLaunchingWithOptions:) 在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];
    }

Update below methods in you appDelegate.m 在您的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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM