xcode 为推送通知注册 iPhone 应用程序不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8893466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Registering the iPhone application for push notification not working
提问by Vinod
I have tried out the example found in the link http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12, for my iPhone push notification message. I could successfully run all steps except the steps for registering the app for push notification for the first time.
我已经尝试了在链接http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12 中找到的示例,用于我的 iPhone 推送通知消息。除了第一次为推送通知注册应用程序的步骤之外,我可以成功运行所有步骤。
I have followed different variations of the code:
我遵循了代码的不同变体:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
But none worked for me. I am testing it in my iPhone 4 and my Xode version is 4.2 , OS is Lion. Please advice.
但没有一个对我有用。我正在我的 iPhone 4 上测试它,我的 Xode 版本是 4.2 ,操作系统是 Lion。请指教。
回答by nduplessis
You can try the following:
您可以尝试以下操作:
- Make sure your Xcode project is configured to use the explicit bundle ID from the provisioning portal
- Make sure you're not building the target with wildcard or team provisioning profile, check this on the project ANDtarget settings
- If you created your provisioning profile before configuring the app ID for push, regenerate the provisioning profile
- 确保您的 Xcode 项目配置为使用配置门户中的显式包 ID
- 确保您没有使用通配符或团队配置文件构建目标,请检查项目和目标设置
- 如果您在为推送配置应用 ID 之前创建了配置文件,请重新生成配置文件
Also look at the error object in the UIApplicationDelegate method
还要看UIApplicationDelegate方法中的error对象
application:didFailToRegisterForRemoteNotificationsWithError:
EDIT 1
编辑 1
Open your provisioning profile in a text editor and look for the string
在文本编辑器中打开您的配置文件并查找字符串
<key>aps-environment</key>
If your profile does not contain this, it is not correctly set up for push.
如果您的个人资料不包含此内容,则说明未正确设置推送。
回答by Marek Sebera
Here is my workin code sample from application delegate (AppDelegate.m
)
这是我来自应用程序委托 ( AppDelegate.m
) 的工作代码示例
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
}
To check if registration went OK, implement these three methods
要检查注册是否成功,请实现这三个方法
– application:didReceiveRemoteNotification:
– application:didRegisterForRemoteNotificationsWithDeviceToken:
– application:didFailToRegisterForRemoteNotificationsWithError:
Or you can go to Settingsto see if there is permissions settings available
或者你可以进入设置查看是否有可用的权限设置
like this:
像这样:
回答by ikarius
If this problem appears in production (with your application on the appStore), it's very likely because you created/enabled the APNS production mode of your application AFTERhaving created the distribution profile.
如果此问题出现在生产中(您的应用程序在 appStore 上),很可能是因为您在创建分发配置文件后创建/启用了应用程序的 APNS 生产模式。
In this case, no other option but to submit again with a correct certificate...
在这种情况下,别无选择,只能用正确的证书再次提交......
Rule of thumb: ALWAYSenable/create production certificate for your application BEFOREcreating the distribution profile.
经验法则:在创建分发配置文件之前,始终为您的应用程序启用/创建生产证书。
You can use the method described by 'nduplessis' (see below) to manually check if you application will run notification once approved.
您可以使用“nduplessis”(见下文)描述的方法来手动检查您的应用程序在获得批准后是否会运行通知。
回答by Максим Мартынов
Go to Capabilities-> Push Notifications. If there are errorsthen try out this solution!
转到功能->推送通知。如果有错误,请尝试此解决方案!
If Xcode version was changedfrom 7 to 8 then try out this solution!
如果Xcode 版本从 7更改为 8,请尝试此解决方案!
Xcode 7 copies the aps-environment entitlement from your provisioning profile. Turning on push notifications on Xcode 8 adds the entitlement both to your provisioning profile and the entitlements file.
Xcode 7 从您的配置文件中复制 aps-environment 权利。在 Xcode 8 上打开推送通知会将权利添加到您的配置文件和权利文件中。
Try adding the aps-environment entitlement to your app's entitlements file, or switch the notification capability off and on again.
尝试将 aps-environment 权利添加到您的应用程序的权利文件中,或关闭并重新打开通知功能。
回答by jodm
Have you ever seen the push notification dialog in your app? If you dismiss the dialog it takes 24 hours to reshow. Check this by setting the time on your iPhone ahead by 2 days and see if it shows.
你有没有在你的应用程序中看到推送通知对话框?如果您关闭对话框,则需要 24 小时才能重新显示。通过将 iPhone 上的时间提前 2 天进行检查,看看它是否显示。
Also have you implemented the delegate methods:
你还实现了委托方法:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
Try putting an NSLog(@"") in the didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError and see it is is getting in there?
尝试将 NSLog(@"") 放在 didRegisterForRemoteNotificationsWithDeviceToken 和 didFailToRegisterForRemoteNotificationsWithError 中,看看它是否在那里?
Also you require an App Id that is setup for Push notification and you need to have generated the Push notification certificates to send the messages.
您还需要一个为推送通知设置的应用程序 ID,并且您需要生成推送通知证书才能发送消息。
回答by Sree
You can only register it with a provisioning profile having an app id with push notification services enabled.please Check those steps also.This a good tutorial for starting push notification http://mobiforge.com/developing/story/programming-apple-push-notification-services
您只能使用具有启用推送通知服务的应用程序 ID 的配置文件注册它。请同时检查这些步骤。这是开始推送通知的好教程http://mobiforge.com/developing/story/programming-apple-push -通知服务