推送通知没有在更新后的版本从ios7努力ios8.1 [英] Push notifications are not working in updated version from ios7 to ios8.1

查看:189
本文介绍了推送通知没有在更新后的版本从ios7努力ios8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了我的设备从ios7到ios8.1.Push通知不会在更新版本的工作。
我做了这是在做ios7推送通知同样的过程。
在code也更新

I updated my device from ios7 to ios8.1.Push notifications are not working in updated version. I did same process for push notifications which is done in ios7. The code is also updated

    #ifdef __IPHONE_8_0
      //Right, that is the point
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge
    |UIUserNotificationTypeSound
    |UIUserNotificationTypeAlert) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#else
    //register to receive notifications
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
#endif

通过使用上述code还我因此未得到notification.Please帮助我在ios8.1推送通知。

By using the above code also i didnot get notification.Please help me for push notifications in ios8.1.

inadvance

thanks inadvance

推荐答案

用于接收推送通知的方法也发生了变化:

The method for receiving a push notification has also changed:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier

请参阅处理本地和远程通知和<一个href=\"https://developer.apple.com/library/ios/documentation/uikit/reference/uiapplicationdelegate_protocol/index.html\"相对=nofollow> UIApplicationDelegate 了解更多信息。

See Handling Local and Remote Notifications and UIApplicationDelegate for more info.

下面是一个应用程序委托的一个完整的例子:

Here is a full example of an application delegate:

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        NSLog(@"Requesting permission for push notifications..."); // iOS 8
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:
            UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
            UIUserNotificationTypeSound categories:nil];
        [UIApplication.sharedApplication registerUserNotificationSettings:settings];
    } else {
        NSLog(@"Registering device for push notifications..."); // iOS 7 and earlier
        [UIApplication.sharedApplication registerForRemoteNotificationTypes:
            UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |
            UIRemoteNotificationTypeSound];
    }
    return YES;
}

- (void)application:(UIApplication *)application
    didRegisterUserNotificationSettings:(UIUserNotificationSettings *)settings
{
    NSLog(@"Registering device for push notifications..."); // iOS 8
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
{
    NSLog(@"Registration successful, bundle identifier: %@, device token: %@",
        [NSBundle.mainBundle bundleIdentifier], token);
}

- (void)application:(UIApplication *)application
    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Failed to register: %@", error);
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier
    forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler
{
    NSLog(@"Received push notification: %@, identifier: %@", notification, identifier); // iOS 8
    completionHandler();
}

- (void)application:(UIApplication *)application
    didReceiveRemoteNotification:(NSDictionary *)notification
{
    NSLog(@"Received push notification: %@", notification); // iOS 7 and earlier
}

这篇关于推送通知没有在更新后的版本从ios7努力ios8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆