iPhone客户端没有注册推送?

时间:2011-09-28 22:51:43

标签: iphone ipad push-notification apple-push-notifications

我“认为”我的应用没有注册推送通知。

它应该像将代码添加到didFinishLaunchingWithOptions一样简单,然后测试推送通知的应用程序警报应该(但不是在我的情况下)弹出。

我的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

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

return YES;
}

这是一款iPad应用。它在没有推送我的真实设备的情况下运行,所以我认为配置是正确的。

有什么想法吗?我没有得到推动不允许/确定弹出。

push

3 个答案:

答案 0 :(得分:1)

你的代表中有这个代码吗?

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

    NSString *str = [NSString 
        stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(str);

}

您应该生成设备令牌,并将其放在您要推送通知的服务器中。

如果让你说iphone部件上的一切正常,问题可能出在您推送通知的服务器代码上..

看一下关于推送通知的本教程: http://mobiforge.com/developing/story/programming-apple-push-notification-services

答案 1 :(得分:1)

您需要实现委托方法并在服务器上设置证书。以下是objc方面的一些代码:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"token"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithString:@""] forKey:@"token"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] 
                                                     message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] 
                                                    delegate:self 
                                           cancelButtonTitle:@"OK" 
                                           otherButtonTitles:nil] autorelease];
    [alert show];
}

答案 2 :(得分:0)

是的我也有代码的其他部分。我的印象是,弹出窗口会发生在天气服务器的东西还没有完成的时候?

我得到了它的工作。我必须得到一个新的配置文件。删除旧的。进入app文件夹。查看项目文件的内容。使用文本编辑器打开包含配置键的文件,并使用新的密钥代码将密钥(两个点)交换出来。

现在它有效。谢谢你的帮助。