0

我已经按照本教程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; }
4

3 回答 3

1

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

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

NSString *token = [[devToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"token: %@", token);
} 
于 2013-11-02T11:22:43.483 回答
1

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

还是没有通知发送给您?

于 2013-11-02T10:49:49.337 回答
0

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

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

于 2014-07-16T11:13:21.307 回答