我试图设置Urban Airship,以便在没有运气的情况下向我的iOS应用程序发送推送通知。
以下是我的事情:
以下是我的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。
答案 0 :(得分:3)
我明白了 - 我一定错过了文档中的这一行:
[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
applicationState:application.applicationState];