ios - 无法通过 APNS 获得推送通知

标签 ios iphone ipad apple-push-notifications

我已遵循本教程 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; }

最佳答案

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

- (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/

相关文章:

ios - 在@selector 方法中传递参数

ios - 为什么插入耳机时 iPhone 底部麦克风的音量与不插入时不同?

ios - 解析.com : Searching a TableView

ios - 从 NSCFString 获取 NSString

objective-c - UISplitViewController 以编程方式没有 nib/xib

video - iPad 上的 HTML5 视频

ios - 缺少返回 UITableViewCell

iphone - 什么时候在 iOS 中使用 layoutSubview

iphone - 我多久可以在 App Store 上更新一次我的应用程序?

iphone - PWA 可以访问联系人、GPS 或使用手机摄像头吗?