首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS8.1无法接收苹果推送

iOS8.1无法接收苹果推送
EN

Stack Overflow用户
提问于 2014-11-12 11:38:56
回答 3查看 231关注 0票数 1

当用户第一次使用我们的应用程序时,他们会收到一个提醒,要求他们接收苹果推送。设备的操作系统版本为ios 8.0或later.User允许请求。ios8.0设备可以接收苹果推送,但ios8.1不能。我使用以下代码:

代码语言:javascript
复制
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
 not use:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];

我不知道错误是什么!有人能帮我吗?谢谢!

EN

回答 3

Stack Overflow用户

发布于 2014-11-12 11:51:31

我也遇到过同样的问题,下面的代码对我有帮助!在iOS 8中,注册远程通知的方式已更改。

代码语言:javascript
复制
 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
                                                                                 settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
                                                                                 categories:nil]];


            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
                    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
票数 1
EN

Stack Overflow用户

发布于 2014-11-12 11:45:29

尝试使用"show“而不是"push”,因为后者已被弃用,这是一个提示,表明以后将不再使用它。

票数 0
EN

Stack Overflow用户

发布于 2014-11-12 12:23:01

您应该在appDidFinishLaunchAppDelegate中为ios7 &iOS8添加以下代码

代码语言:javascript
复制
/*--- Setup Push Notification ---*/
//For iOS 8
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)] && [UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)])
{
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
//For iOS 7 & less
else if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotificationTypes:)])
{
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}

也许你不需要这个,但是如果你需要接收远程通知方法

代码语言:javascript
复制
#pragma mark - For Remote Notification
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
//handle the actions
//    if ([identifier isEqualToString:@"declineAction"]){
//    }
//    else if ([identifier isEqualToString:@"answerAction"]){
//    }
}
#endif

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *device_Token = [[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

 // show some alert or otherwise handle the failure to register.
 NSLog(@"error : %@",error.localizedDescription);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [self SetUpActionWhenPushNotiClicked:userInfo application:application PushPop:NO];
}
-(void)SetUpActionWhenPushNotiClicked:(NSDictionary*)userInfo application:(UIApplication *)application PushPop:(BOOL)pushpop
{
NSLog(@"UserInfo : %@",userInfo);
application.applicationIconBadgeNumber = 0;
if (userInfo)
{
    if (application.applicationState == UIApplicationStateActive )
    {
        //NSLog(@"app is already open");
    }
    else if (application.applicationState == UIApplicationStateBackground ||
             application.applicationState == UIApplicationStateInactive)
    {
        //NSLog(@"app is coming from bg");
    }
}

}

也许这会对你有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26878844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档