【发布时间】:2013-02-07 21:55:29
【问题描述】:
我尝试设置 Urban Airship 以向我的 iOS 应用程序发送推送通知,但没有成功。
这是我拥有的东西:
- 已启用推送通知的开发人员配置文件
- 在设备上推送通知证书并上传到 Urban Airship
- 任何地方都没有错误 - UA 的错误控制台是空的,我检查了我的设备令牌是否处于活动状态
这是我的 AppDelegate.m 文件中的一些 sn-ps
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Register for notifications
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
[UAirship setLogging:YES];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
// Updates the device token and registers the token with UA
NSLog(@"APN device token: %@", devToken);
[[UAPush shared] registerDeviceToken:devToken];
}
当我通过 UA 的“测试推送通知”选项卡发送通知或通过终端发送 CURL 命令时,不会调用以下任何方法
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@"Error in registration. Error: %@", err.description);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"Received push notification with userInfo:%@", userInfo);
}
- (void)handleNotification:(NSDictionary *)notification applicationState:(UIApplicationState)state
{
NSLog(@"Received push notification with notification:%@", notification);
}
我尝试在应用关闭的情况下发送测试推送通知,而 iOS 也没有执行任何操作。我在 iphone 上检查了设置并转到我的应用程序,它显示为徽章和横幅启用了推送。我在 iPhone 5 上运行 iOS 6.1。
【问题讨论】:
-
从您的描述中,不清楚是否调用了
didRegisterForRemoteNotificationsWithDeviceToken。 -
是的,它正在被调用,我在 UA 的网站上看到了我的设备的设备令牌。
-
好吧,在那种情况下,我能想到的唯一问题是证书。你应该上传正确的证书吗?您使用的是沙盒还是生产证书?您的应用程序是否使用开发或临时/生产配置文件签名?如果配置文件与证书不匹配,Apple 不会发送任何错误指示。
-
我从苹果的 Provisioning Portal 上传了用于签署应用程序的 AppID(具有相同的捆绑 ID)的开发推送 SSL 证书。我使用开发配置文件和开发推送证书。还有其他想法吗?
标签: ios push-notification apple-push-notifications urbanairship.com