首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推送通知未在IOS8.1中交付,但在较少的时间内工作良好

推送通知未在IOS8.1中交付,但在较少的时间内工作良好
EN

Stack Overflow用户
提问于 2014-11-18 08:00:26
回答 1查看 242关注 0票数 0

更新:注意我使用的是Xcode 6.01并使用此代码进行部署,但当我安装Xcode 6.1版本并部署它的works...so版本时,它可能是Xcode版本,这将帮助其他人。

我正在使用下面的代码进行推送通知,使用PARSE.com --在ios8下面的所有设备上都很好,

代码语言:javascript
复制
if (application.applicationState != UIApplicationStateBackground) {
        // Track an app open here if we launch with a push, unless
        // "content_available" was used to trigger a background push (introduced in iOS 7).
        // In that case, we skip tracking here to avoid double counting the app-open.
        BOOL preBackgroundPush = ![application respondsToSelector:@selector(backgroundRefreshStatus)];
        BOOL oldPushHandlerOnly = ![self respondsToSelector:@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:)];
        BOOL noPushPayload = ![launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
            [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
        }
    }

此外,我还使用这些条件进行测试(小于ios 8的工作效率很好)。

如果__IPHONE_OS_VERSION_MAX_ALLOWED >= 80000

代码语言:javascript
复制
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
} else

endif

代码语言:javascript
复制
{
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                     UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}

即使是iOS 8 enabled device not receiving PUSH notifications after code update也不适合我,我正确地设置了通知,我的包标识符集也是正确的。

EN

回答 1

Stack Overflow用户

发布于 2014-11-18 09:15:40

代码语言: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提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26989289

复制
相关文章

相似问题

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