push or local notification

I want the notifications appear when the app get new post from url and when the user tap on notification that take the user to this post

is this work with push or local notification ?

the notifications appear when the app get new post from url

It depends on what precisely means the app get new post from url.
If you mean your app retrieves some post from the url with your code while your app is running, you can use local notifications.
This is my code. is both work with it?





import SwiftUI



struct Response: Decodable {

    var results: [Result]

}



struct Result: Decodable {

    var id: Int

    var link: String

    var title: Title

    var date: String

    var content: Content

    }

struct Title: Decodable {

    var rendered: String

}

struct Content: Decodable {

    var rendered: String

    var protected: Bool

}





struct JobView: View {

    @State private var results = [Result]()

    @State private var isLoading = false

    @State private var alignment = TextAlignment.trailing



      var body: some View {

            ZStack {

            List(results, id: \.id) { item in

                  VStack(alignment: .leading) {

                    

                        VStack{

                            Text(item.title.rendered.withoutHtmlTags)

                              .font(.headline)

                            Text(item.date)

                            

                            NavigationLink(

                                destination: List{

                                    Text(item.title.rendered.withoutHtmlTags)

                                        .fontWeight(.black)

                                        .multilineTextAlignment(alignment)

                                        .font(.title3)

                                        

                                    Text(item.content.rendered.withoutHtmlTags)

                                        .multilineTextAlignment(alignment)

                                }

                                ,label: {

                                    Text("Detail")

                                        .multilineTextAlignment(alignment)

                                })

                            

                        }

                        .padding(.all, 20)

                    

                  }

                  .background(Color.white)

                  .cornerRadius(10)

                  .shadow(color: .green, radius: 1)

                  .multilineTextAlignment(alignment)

            

                

        

        }

                if isLoading {

                    ZStack{

                        Color(.systemBackground)

                            .ignoresSafeArea()

                        ProgressView()

                            .progressViewStyle(CircularProgressViewStyle(tint: .green))

                            .scaleEffect(2)

                    }

                }

                

        }

          

          .onAppear(perform: loadData)

          .onAppear{startFakeNetworkCall()}

          }

    func startFakeNetworkCall() {

        isLoading = true

        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {

            isLoading = false

        }

    }

    func loadData() {

        guard let url = URL(string: "") else {

            print("Invalid URL")

            return

        }

        

        let request = URLRequest(url: url)

        

        URLSession.shared.dataTask(with: request) { data, response, error in

            if let data = data {

                if let decodedResponse = try? JSONDecoder().decode([Result].self, from: data) {

                    

                    DispatchQueue.main.async {

                        

                        self.results = decodedResponse

                    }



                    

                    return

                }

            }



            print("Fetch failed: \(error?.localizedDescription ?? "Unknown error")")

            

        }.resume()

        

        

      }

  }


This is my code. is both work with it?

What does both mean? Including push notifications?
You need to communicate to your server in order to send push notification. Is your server ready for it?
Is background fetch work with API ?

Is background fetch work with API ?

What do you mean? Can you be more specific?
I mean I get data from server by API the data take time to load I want to refresh data automatically in background

I mean I get data from server by API the data take time to load I want to refresh data automatically in background

I may not be understanding what you mean yet, but it would work. Though, I have never tried to do background tasks with SwiftUI.
push or local notification
 
 
Q