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

最佳答案

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

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

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

关于ios - 没有通过APNS收到推送通知,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19741045/

10-13 06:16