首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通知内容未被调用,甚至连内容情节提要都被更新。

通知内容未被调用,甚至连内容情节提要都被更新。
EN

Stack Overflow用户
提问于 2019-07-10 09:31:42
回答 1查看 200关注 0票数 0

我试着用图片做推送通知。

下面是我从pushtry.com发送的推送

代码语言:javascript
复制
{
  "aps": {
    "alert": "message with meow image 11",
    "badge": 1,
    "sound": "default",
   "category": "DCCPush",
   "mutable-content": "1"
  },
  "Type": "product",
  "Id": 165,
  "imageURL": "https://i.stack.imgur.com/FXmv3.jpg"
}

推来我的形象,但问题是,当我拉下推,形象没有显示。请看下面的截图。

当我被图像推送时,我知道通知服务正在工作。如果我错了请纠正我。

现在,我觉得通知内容不工作,所以我所做的是添加标签与背景颜色为橙色。

下面是我在UI中为图像所做的。

当您看到第二个图像时,我们看不到这个橙色标签意味着Notification不工作。

我在跟踪本教程制作图片推送。

下面是我在中的内容

代码语言:javascript
复制
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    let notificationDelegate = SampleNotificationDelegate()

    func configureNotification() {
        if #available(iOS 10.0, *) {
            let center = UNUserNotificationCenter.current()
            center.requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in }
            center.delegate = notificationDelegate
            let openAction = UNNotificationAction(identifier: "OpenNotification", title: "clickToView".localized(), options: UNNotificationActionOptions.foreground)
            let deafultCategory = UNNotificationCategory(identifier: "DCCPush", actions: [], intentIdentifiers: [], options: [])
            center.setNotificationCategories(Set([deafultCategory]))
        } else {
            UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
        }
        UIApplication.shared.registerForRemoteNotifications()
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.


        self.configureNotification()

下面是我在SampleNotificationDelegate中的内容

代码语言:javascript
复制
import UIKit

import Foundation
import UserNotifications
import UserNotificationsUI

class SampleNotificationDelegate: NSObject , UNUserNotificationCenterDelegate {

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert,.sound])
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        switch response.actionIdentifier {
        case UNNotificationDismissActionIdentifier:
            print("Dismiss Action")
        case UNNotificationDefaultActionIdentifier:
            print("====Open Action======")

            print("response===\(response)")

            let userInfo = response.notification.request.content.userInfo
            PushNotificationResponse(Data:userInfo as NSDictionary)


        case "Snooze":
            print("Snooze")
        case "Delete":
            print("Delete")
        default:
            print("default")
        }
        completionHandler()
    }

    func PushNotificationResponse(Data:NSDictionary){

        DispatchQueue.main.asyncAfter(deadline: .now() + 1) { // change 2 to desired number of seconds

             switch (Data["Type"] as! String) {

                case "product":

                    print("push details")

                    UserDefaults.standard.set(Data["Id"] as? Int, forKey: "pushId")
                    UserDefaults.standard.synchronize()

                    Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.prepareDataNotifications), userInfo: nil, repeats: false)
                    break
            default:
                break

            }
        }

    }

    @objc func prepareDataNotifications() {
        var mProduct : Products = Products()
        mProduct.id = UserDefaults.standard.integer(forKey: "pushId")
        Transition.openProductDetailsVCScreen2(withAnimation: true, productObject: mProduct)
    }

}

下面是Info.plist在内容上的截图

知道我错过了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-13 09:05:56

问题是NotificationViewController在内容上没有标记为“初始视图控制器”

这是因为我将旧项目的视图控制器复制到当前项目中。:)

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

https://stackoverflow.com/questions/56967683

复制
相关文章

相似问题

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