简体   繁体   English

iPhone客户端没有注册推送?

[英]iPhone client not registering for push?

I "think" my app is not registering for push notifications. 我“认为”我的应用程序没有注册推送通知。

It should be as simple as adding the code to didFinishLaunchingWithOptions and then the when tested the app alert for push notifications should (but does not in my case) pop up. 它应该像将代码添加到didFinishLaunchingWithOptions一样简单,然后测试推送通知的应用程序警报应该(但不是在我的情况下)弹出。

my code: 我的代码:

- (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;
}

This is an iPad app. 这是一款iPad应用。 It is running without push on my real device so I assume the provisioning is correct. 它在没有推送我的真实设备的情况下运行,所以我认为配置是正确的。

Any ideas? 有任何想法吗? I do not get the push Don't allow/ok pop up. 我没有得到推动不允许/确定弹出。

推

Do u have this code in your delegate? 你的代表中有这个代码吗?

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

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

}

You should get the device token generated and put it in your server where you want to push your notification.. 您应该生成设备令牌并将其放在要推送通知的服务器中。

If let say you have everything right on the iphone part, the problem may lies on your server code where you push your notification.. 如果让你说iphone部件上的一切正常,问题可能在于您推送通知的服务器代码。

Take a look at this tutorial about push notification : http://mobiforge.com/developing/story/programming-apple-push-notification-services 看看这个关于推送通知的教程: http//mobiforge.com/developing/story/programming-apple-push-notification-services

You need to implement the delegate methods and set up the certificates on your server. 您需要实现委托方法并在服务器上设置证书。 Here is some code for the objc side: 以下是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];
}

Yes I have the other part of the code also. 是的我也有代码的其他部分。 I was under the impression that the pop up would happen weather the server stuff was done yet or not? 我的印象是,弹出窗口会发生天气,服务器的东西还没有完成?

I got it working. 我搞定了。 I had to get a new provisioning file. 我必须得到一个新的配置文件。 Delete the old one. 删除旧的。 The go into the app folder. 进入app文件夹。 View contents of the project file. 查看项目文件的内容。 Open with text editor the file with the provisioning key in it and swap the key (two spots) out with the new key code. 使用文本编辑器打开包含配置键的文件,并使用新的密钥代码将密钥(两个点)交换出来。

Now it works. 现在它有效。 Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM