![](/img/trans.png)
[英]Apple Push Notification Service APNS - Notifications not arriving
[英]APNS Apple Push Service Notification not recieving
我已使用APNS Apple Push Service Notification的代碼消息正在從服務器發送,但未接收到設備。 檢查以下URL:
https://indiegirlworld.com/app/license_iphone/sample_push.php
以下是我從上述鏈接獲得的消息:
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]:信息:正在發送消息隊列,運行#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]:信息:已斷開連接。
您是否簽入了將推送通知設置為“開”的設置?
另外,推送通知只能在Real設備中而不在Simulators中接收。
您可以從模擬器發送推送通知(因為這只是一個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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.