无法在 iOS8 上设置交互式推送通知

2024-02-19

我已经能够设置交互式本地通知,但远程通知不起作用。我正在使用 Parse.com 发送 JSON

我的 AppDelegate.Swift 看起来像这样:

//
//  AppDelegate.swift
//  SwifferApp
//
//  Created by Training on 29/06/14.
//  Copyright (c) 2014 Training. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        UINavigationBar.appearance().barTintColor = UIColor.orangeColor()
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()


        Parse.setApplicationId("eUEC7O4Jad0Kt3orqRouU0OJhkGuE20n4uSfrLYE", clientKey: "WypmaQ8XyqH26AeWIANttqwUjRJR4CIM55ioXvez")

        let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
        let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)

        UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)

        return true
    }

    func application(application: UIApplication!, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings!) {
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }

    func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
        let currentInstallation:PFInstallation = PFInstallation.currentInstallation()
        currentInstallation.setDeviceTokenFromData(deviceToken)
        currentInstallation.saveInBackground()
    }

    func application(application: UIApplication!, didFailToRegisterForRemoteNotificationsWithError error: NSError!) {
        println(error.localizedDescription)
    }

    func application(application: UIApplication!, didReceiveRemoteNotification userInfo:NSDictionary!) {

        var notification:NSDictionary = userInfo.objectForKey("aps") as NSDictionary

        if notification.objectForKey("content-available"){
            if notification.objectForKey("content-available").isEqualToNumber(1){
                NSNotificationCenter.defaultCenter().postNotificationName("reloadTimeline", object: nil)
            }
        }else{
            PFPush.handlePush(userInfo)
        }
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
}

在 Parse 上,我将 Push 负载设置为如下:

{
"alert": "Tune in for the World Series, tonight at 8pm EDT",
"badge": "Increment",
"sound": "chime",
"category": "FIRST_CATEGORY"
}

我收到了推送,但不是使用我设置的自定义按钮。


我不确定我的问题是否与您的问题相同(确保您的问题不是由于 Parse 引起的)。只要在这里发布我的解决方案,以防其他人遇到同样的问题。

我的问题出在通知类别中。

确保您在注册通知设置时设置了类别(我使用的是 Objective-C,没有太大区别):

UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
            notificationCategory.identifier = @"CallNotificationCategory";
            [notificationCategory setActions:@[declineAction, answerAction] forContext:UIUserNotificationActionContextDefault];

            NSSet *categories = [[NSSet alloc] initWithObjects:notificationCategory, nil];

并且,当您发送远程通知时,请确保有效负载中有“类别”,并且该值与您在客户端中定义的值相同。就我而言,它是这样的:

{
  "alert": "Tune in for the World Series, tonight at 8pm EDT",
  "badge": "Increment",
  "sound": "chime",
  "category": "CallNotificationCategory"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 iOS8 上设置交互式推送通知 的相关文章

  • 解析:无效的用户名、密码

    我正在使用数据库的 Parse API 并尝试使用它提供的用户名服务 我从教程中了解到 为了登录 您需要执行以下操作 ParseUser logInInBackground Jerry showmethemoney new LogInCal
  • 使用 Swift 获取 UITableViewCell 中 UITextField 的 indexPath

    因此 我正在构建一个详细视图控制器应用程序 它显示一个包含两部分单元格的表格 标签和文本字段 我正在尝试检索文本字段值并将其添加到数组中 我尝试使用 textField superview superview 技术 但没有成功 func t
  • 获取沙箱用户的 App Store 收据失败,并显示密码错误消息

    我在 Mac App Store 中分发了一个商业 macOS 应用程序 现在 在启动时 我会检查 App Store 收据 如果不存在 则以代码 173 退出 这将打开 App Store 登录对话框以获取收据 我一直使用沙盒帐户对此进行
  • 无法读取未定义的属性“messageHandlers”

    我想将 JavaScript 变量传递给 Swift 我在 JavaScript 中遇到错误并进行了搜索 但没有得到任何结果 错误是 类型错误 无法读取未定义的属性 messageHandlers 任何人都可以帮忙吗 我在 Xcode 中的
  • 为 MoonAPNS 创建 p12 文件时卡住了

    我在创建 p12 证书时遇到一些问题 我之前创建了一个带有推送通知的应用程序 效果很好 应用程序获取用户设备 ID 并将其保存到数据库中 我已将代码添加到我的新应用程序中 并进行了与新应用程序一起使用的修改 从日志来看 它的工作方式似乎与我
  • 我什么时候应该将可选值与 nil 进行比较?

    很多时候 您需要编写如下代码 if someOptional nil do something with the unwrapped someOptional e g someFunction someOptional 这似乎有点冗长 而且
  • 在 Swift 中将进程标准输出重定向到 Apple 系统日志工具

    我正在为 macOS 构建一个启动子进程的 Swift 应用程序 该子进程将有用的信息记录到stdout 我在 Xcode 控制台中看到它 我现在想要实现的是重定向子流程stdout到Apple Log Facility 以便我们可以在部署
  • 使用 AVFoundation 快速获取视频帧

    这是我的代码 我想要获取我的视频并将帧数据获取到 SceneKit SCNSphere NSString videoPath NSBundle mainBundle l var videoURL NSBundle mainBundle UR
  • iOS 12.1 上的 UITabBar 项目在返回导航上跳跃

    我有一个 iOS 应用程序UITabBarController在主屏幕上 导航到隐藏的详细信息屏幕UITabBarController有设置hidesBottomBarWhenPushed true 返回主屏幕时UITabBarContro
  • 将属性类型作为参数传递

    有没有办法将属性作为参数传递给函数 class Car let doors Int 4 let price Int 1000 有没有办法将 Car 属性作为类型传递给函数 我想实现以下目标 func f1 car Car property
  • 在 Swift 中枚举多个具有相同值的情况

    在 C 中 你可以让你的枚举具有以下内容 typedef enum Bar A 0 B 0 C 1 Bar 在 Swift 中我想做等价的事情 然而 编译器抱怨它不是唯一的 我如何告诉它我希望两个案例具有相同的值 enum Bar Int
  • 在 Swift 3 中从 UUID 获取数据

    我用 Objective C 编写了以下代码 我试图在 Swift 3 中使用它 一些等效函数似乎在 Swift 3 中不可用 下面的代码是 Objective C 中的代码 NSUUID vendorIdentifier UIDevice
  • 仅为 UITableView 中的某个部分启用编辑模式

    我有一个tableView其中有一个可编辑的部分 如果我启用整个编辑tableView 其他单元格在编辑模式下不是selectable 所以我需要仅在特定部分启用编辑模式 以便其他单元格selectable 该部分是可编辑的 我需要设置编辑
  • 如何使用UIPageViewController跳转到特定页面?

    我正在使用 Xcode 8 的默认基于页面的应用程序 并且我一直在尝试跳转到特定页面 而不是左右滑动来转动 我在 StackOverflow 上发现了类似的问题 但答案大多建议使用这种方法 setViewControllers direct
  • 如何将LUT png用于CIColorCube滤镜?

    我想使用查找表 png example http nghiatran me wp content uploads 2014 06 FilterMe Part2 ProcessedLUT png 作为颜色立方体数据CIColorCubeSwi
  • 下标的使用不明确

    该代码块以前可以工作 但现在不行了 我在纬度和经度变量上收到错误 下标 的使用不明确 这是怎么回事 这是因为 Swift 更新吗 func showPrecincts var urlBoundaries http www oklahomad
  • NSTimer 每分钟运行一次,但在第一秒运行

    我有使用 NSTimer 每分钟运行一次的经验 例如 NSTimer scheduledTimerWithTimeInterval 60 0 target self selector Selector everyMinute userInf
  • 如何按日期正确对从 CoreData 获取的列表进行分组?

    为了简单起见 假设我想创建一个简单的待办事项应用程序 我的 xcdatamodeld 中有一个实体 Todo 其属性id title and date 以及以下 swiftui 视图 如图所示的示例 import SwiftUI struc
  • 从 CMSampleBuffer 播放音频

    我在 iOS 中为群组创建了一个视频聊天应用程序 我一直在寻找一些方法来分别控制不同参与者的音频音量 我找到了使用静音和取消静音的方法isPlaybackEnabled in RemoteAudioTrack 但不控制音量 我还想我们是否可
  • 由于某种原因,AdColony 的 AdReward 无法在 Swift 2.0 上运行

    我想在我的游戏中实现奖励插页式广告 但我收到了很多 AdColony 错误 例如 未填写广告请求 或我的区域 ID 无效 首先 这就是我配置 AdColony 区域的方式 Zone is active Yes Zone Type Prero

随机推荐

  • SPSite 站点 = new SPSite(SPContext.Current.Web.Url) 与 SPContext.Current.Web.Site

    为什么某些 SharePoint 示例使用 using SPSite site new SPSite SPContext Current Web Url 而不仅仅是简单地 SPSite site SPContext Current Web
  • 如何使用DELPHI更改Android设备通知中的小图标图像

    有没有办法用Delphi更改Android应用程序通知中的小图标图像 默认使用的应用程序图标 轻松创建通知的标准方法是 var aNotification TNotification begin aNotification aNotific
  • 在C++中查找进程中加载​​的DLL的内存地址

    我有一个正在使用 Test dll 的正在运行的进程 我想知道内存中 Test dll 开始的确切内存位置 但似乎无法 我的主要问题是我需要写入此 DLL 的偏移量 但当我使用 Read WriteProcessMemory 时 我无法准确
  • 为什么 MassTransit 消息传递中不允许使用结构体?

    消费者界面在MassTransit所有人都期望消息模型是类而不是结构 由于它们都是内部接口 我必须说那里的设计非常好 这是显示约束的通用容器类 直接获取从源代码来看 https github com MassTransit MassTran
  • C++ 打印当前函数输入参数类型、名称和值

    我正在寻找一种允许记录函数输入参数的功能 例如 void func std string input name const int n print current function s inputs type name and value
  • 获取 i18next 以回退到“无翻译”

    如果没有找到该键的翻译 默认情况下 i18next 翻译库似乎会回退到翻译键 例如 No translation defined for CANCEL yet i18next t CANCEL Returns CANCEL 如果没有找到该密
  • 如何动态创建变量? [复制]

    这个问题在这里已经有答案了 我想在Python中动态创建变量 有没有人有任何创造性的方法来做到这一点 除非非常需要创建一堆变量名称 否则我只会使用字典 您可以在其中动态创建键名称并将值与每个名称相关联 a k 0 while k lt 10
  • 将一组 NumPy 数组传递到 C 函数中进行输入和输出

    假设我们有一个 C 函数 它接受一组一个或多个输入数组 处理它们 并将其输出写入一组输出数组 签名如下所示 count表示要处理的数组元素的数量 void compute int count float input float output
  • 使用 Webpack 和 ES6 的 Fine Uploader

    我正在尝试将 Fine uploader 与通过 Webpack 捆绑的 React ES6 应用程序集成 寻找有关如何将精细上传器包含在此堆栈中的指导 In my webpack config js我为 Fine Uploader 设置了
  • 在javascript中使用单引号传递变量

    我对链接进行了 onClick 调用 a this is working good 问题是 fomateName 内的变量将包含单引号 而我的 fomateName 采用如下变量 var a Andrew D souza 需要格式化用单引号
  • 定义指向 const 字符串的 const 指针

    阅读了 Ulrich Drepper 的博文 发现两个条目看起来相互矛盾 In the 第一 http udrepper livejournal com 13851 html 全局空间中的字符串 Ulrich 指出该字符串应定义为 cons
  • Linux下如何用C写文件?

    我想重写Linux的 cp 命令 所以这个程序会像这样工作 a out originalfile copiedfile 我可以打开文件 创建新文件 但无法写入新文件 什么也没写 可能是什么原因 当前的C代码是 include
  • 无法将类型“TEnum”转换为“int”

    我正在尝试将枚举转换为列表 如中所述this https stackoverflow com questions 3489453 how can i convert an enumeration into a listselectlisti
  • 降低 jquery UI 中手风琴的速度

    我对这段代码有两个问题 首先我想降低效果的速度 其次 就像您对效果进行操作以关闭选项卡一样 然后将出现以下新选项卡 if sidebar ul length sidebar ul accordion event mouseover acti
  • 从 SQLite 中的 INSERT OR IGNORE 语句查找自动递增值

    我有一个名为 图像 的表 CREATE TABLE images id INTEGER PRIMARY KEY AUTOINCREMENT url TEXT NOT NULL UNIQUE caption TEXT 插入行时 我希望 URL
  • `npm install` 和 `npmaudit` 计数之间的区别?

    最近添加后npm audit 用于审核依赖关系 我注意到有多少个包之间存在巨大差异added 安装在node modules 以及有多少个audited by npm 这是一个例子 这是我的问题 我说得对吗281已安装的软件包总数是多少 W
  • Selenium 单击与文本对应的 JavaScript 按钮

    我的网页中有很多按钮 它们也是 javascript 按钮 所有这些按钮都有相同的 TagName 但 id 不同 但我不能使用 ID 因为我无法预测必须单击哪个按钮 Selenium 将搜索内容 问题here https stackove
  • 在网络上创建电子邮件表单时的安全注意事项

    我知道我必须考虑 邮件头注入 还有更多的事情吗在发送表格邮件之前我需要知道吗 我想要邮件 我觉得我必须设置表单邮件在我的页面上 但我听说邮件事情很危险 如果我 不考虑所有安全问题 1 避免垃圾邮件 使用验证码或其他东西来防止垃圾邮件 链接谈
  • 返回位于本地堆栈上的块

    clang 分析器可以检查返回的基于堆栈的内存 dispatch block t getPrintBlock const char msg return printf s msg 引发此错误 returning block that liv
  • 无法在 iOS8 上设置交互式推送通知

    我已经能够设置交互式本地通知 但远程通知不起作用 我正在使用 Parse com 发送 JSON 我的 AppDelegate Swift 看起来像这样 AppDelegate swift SwifferApp Created by Tra