【问题标题】:Doesn't get Push Notification with APNS没有通过 APNS 获得推送通知
【发布时间】:2013-11-02 10:37:39
【问题描述】:

我已经按照这个教程http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

如教程中所述,通知已从服务器成功发送。但我没有在我的设备中得到它。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    if(![[NSUserDefaults standardUserDefaults] valueForKey:@"UUID"])
    {
        if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
        {
            deviceID = [self GetUUID];
        }
        else
        {
            NSUUID* udid= [UIDevice currentDevice].identifierForVendor;
            deviceID = [udid UUIDString];
        }
        [[NSUserDefaults standardUserDefaults] setValue:deviceID forKey:@"UUID"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else
    {
        deviceID = [[NSUserDefaults standardUserDefaults] valueForKey:@"UUID"];
    }

    return YES; }

- (NSString *)GetUUID {
        CFUUIDRef theUUID = CFUUIDCreate(NULL);
        CFStringRef string = CFUUIDCreateString(NULL, theUUID);
        CFRelease(theUUID);
        return (__bridge NSString *)string; }

【问题讨论】:

  • UUID 与交付 APNS 无关 - 您的代码不会显示您如何获取 APNS 令牌以及是否将其发送到服务器并以某种方式存储在那里。 David Wong 的回答可能会为您指明正确的方向。另请检查this post 这与您的问题不完全相同,但可能会提供一些说明。
  • didReceiveRemoteNotification: 的一个经过测试的实现可以在 here 找到
  • 还有一件事:如果您今天刚刚创建了 APNS 证书,您可能只需要等待几个小时。

标签: ios iphone ipad apple-push-notifications


【解决方案1】:

对于推送通知,您必须使用推送通知令牌进行注册。 iOS 返回带有空格的推送通知令牌,您必须删除它们:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{

NSString *token = [[devToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"token: %@", token);
} 

【讨论】:

  • 是的,我完全按照教程做了。他们将设备令牌放在 .php 文件中的位置。问题在于在设备中接收通知。
  • 您是否在 Apple Dev Portal 中创建了适当的证书和配置文件?
  • 是的,当我第一次安装应用程序时,它要求我启用推送通知服务。
  • 这并不意味着证书是正确的,这只是意味着您在应用程序委托中添加了推送通知代码。
【解决方案2】:

您是否在应用程序委托中实现了application:didReceiveRemoteNotification:?当您在应用程序中收到通知时。

还是没有通知发送给您?

【讨论】:

  • 是的,我有 didReceiveRemoteNotification:
【解决方案3】:

您的有效负载大小是多少?最大长度为 256 字节。如果您的有效负载超过该限制,它可能会说推送已成功发送,但 Apple 会默默地拒绝它。

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    相关资源
    最近更新 更多