我试图设置 Urban Airship 以向我的 iOS 应用程序发送推送通知,但没有成功。
以下是我拥有的东西:
- 启用推送通知的开发人员配置文件
- 在设备上推送通知证书并上传到 Urban Airship
- 任何地方都没有错误 - UA 的错误控制台是空的,我检查了我的设备令牌是否处于活动状态
这是我的 AppDelegate.m 文件中的一些片段
- (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。