vapor / apns

Helpful extensions and abstractions for using APNSwift
MIT License
115 stars 29 forks source link

Cannot find 'APNSAlertNotification' in scope #54

Closed nicolassrod closed 12 months ago

nicolassrod commented 12 months ago

Describe the bug

I'm importing APNS and VaporAPNS and when I want to use the framework I get this error Cannot find 'APNSAlertNotification' in scope I'm using the resources of the documentation https://docs.vapor.codes/advanced/apns/

To Reproduce

Package definition

// swift-tools-version:5.9
import PackageDescription

let package = Package(
    name: "hello",
    platforms: [
       .macOS(.v13)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.83.1"),
        .package(url: "https://github.com/vapor/apns.git", from: "4.0.0"),
    ],
    targets: [
        .executableTarget(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "VaporAPNS", package: "apns"),
            ]
        ),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),

            // Workaround for https://github.com/apple/swift-package-manager/issues/6940
            .product(name: "Vapor", package: "vapor"),
            .product(name: "VaporAPNS", package: "apns"),
        ])
    ]
)

Where I'm using it

import APNS
import VaporAPNS

func routes(_ app: Application) throws {
    app.get("hello") { req async -> String in
        // Custom Codable Payload
        struct Payload: Codable {
            let acme1: String
            let acme2: Int
        }
        // Create push notification Alert
        let dt = "70075697aa918ebddd64efb165f5b9cb92ce095f1c4c76d995b384c623a258bb"
        let payload = Payload(acme1: "hey", acme2: 2)
        let alert = APNSAlertNotification(
            alert: .init(
                title: .raw("Hello"),
                subtitle: .raw("This is a test from vapor/apns")
            ),
            expiration: .immediately,
            priority: .immediately,
            topic: "my topic",
            payload: payload
        )
        // Send the notification
        try! await req.apns.client.sendAlertNotification(
            alert,
            deviceToken: dt,
            deadline: .distantFuture
        )

        return "Hello, world!"
    }
}

Errors that xcode throws

Cannot find 'APNSAlertNotification' in scope
Cannot infer contextual base in reference to member 'init'
Cannot infer contextual base in reference to member 'raw'
Cannot infer contextual base in reference to member 'raw'
Cannot infer contextual base in reference to member 'immediately'
Cannot infer contextual base in reference to member 'immediately'

Steps to reproduce the behavior:

  1. Add package with configuration '...'
  2. Send request with options '...'
  3. See error

Environment

dannflor commented 12 months ago

You need to import APNSCore at the top. We'll add that to the documentation.