vapor / apns

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

Fix for infinite loop #27

Closed mackoj closed 3 years ago

mackoj commented 3 years ago

Fix for https://github.com/kylebrowning/APNSwift/issues/100

When using the code below with .package(url: "https://github.com/vapor/apns.git", from: "1.0.0"), and the master branch of kylebrowning/APNSwift. It make an infinite recursion.

func routes(_ app: Application) throws {
    app.get { req in
        return "It works!"
    }

    app.get("hello") { req -> String in
        return "Hello, world!"
    }

  app.get("test") { req in
    req.apns.send(
      .init(title: "Hello", subtitle: "This is a test from vapor/apns"),
      to: "971de327b678069dab8f4ddb6aaa833416a27c98234eb118f65b9cd0e281573f"
    ).map { "sent" }
  }
}

Because in Application+APNS.swift in extension Application.APNS: APNSwiftClient it called the bad send line 78 $0.send. In order to fix it it should have called the send with apnsID parameter.

This is the real fix -> https://github.com/vapor/apns/pull/26

When using vapor/apns and kylebrowning/APNSwift in master it worked as expecte, no infinite recursion.

    .package(url: "https://github.com/vapor/apns.git", .branch("master")),
    .package(url: "https://github.com/kylebrowning/APNSwift.git", .branch("master")),

When using vapor/apns 1.0.0 and kylebrowning/APNSwift in master it had the infinite recursion issue.

    .package(url: "https://github.com/vapor/apns.git", from: "1.0.0"),
    .package(url: "https://github.com/kylebrowning/APNSwift.git", .branch("master")),

When using vapor/apns 1.0.0 with the default version of kylebrowning/APNSwift 2.1.0 in master it worked as expected, no infinite recursion.

    .package(url: "https://github.com/vapor/apns.git", from: "1.0.0"),

When vapor/apns will update to 1.1.0 and kylebrowning/APNSwift to 2.2.0 the issue will not exist anymore.

mackoj commented 3 years ago

In order to have this bug to occur you have to first build and run the project with this.

 .package(url: "https://github.com/vapor/apns.git", from: "1.0.0"),

Then build and run the project with this.

    .package(url: "https://github.com/vapor/apns.git", from: "1.0.0"),
    .package(url: "https://github.com/kylebrowning/APNSwift.git", .branch("master")),

Because if you do it in the reverse order the compiler will work as expected and tell you that the implementation of send in Application+APNS.swift and Request+APNS.swift is not good. because the protocol APNSwiftClient(kylebrowning/APNSwift) have changed in 2.2.0 and so it missing the apnsID parameter.

mackoj commented 3 years ago

Hi,

For this to work properly please consider tagging vapor/apns @siemensikkema or @kylebrowning thanks.

kylebrowning commented 3 years ago

Done