I would like to count the absolute frequency of sharing events (weather temp) when the app goes into the background (after sent mail or sms, share text) i would like to use dictionary ◦ Key (number of days relative to Today, Tomorrow = 1, Day after Tomorrow = 2, etc.) ◦ Value: Number of times this day has already been shared. print thsi dictionary in console.
I don't understand the status of the application, I don't know where I have the moment when I can add +1 to the dictionary, because the weather message has been sent
struct MyView: View {
@State private var isSharePresented: Bool = false
@Environment(\.scenePhase) var scenePhase
@State var dictionary = [0: 0,1:0, 2: 0, 3: 0, 4: 0, 5:0, 6:0, 7:0]
var body: some View {
VStack{
//
ForEach(0..<8) { index in
HStack{
HStack{
Text("\(String(format: "%.1f",
daily.temperature2MMin[index])) °C ").padding(10)
Spacer()
Text("\(String(format: "%.1f",
daily.temperature2MMax[index])) °C ").padding(10)
}
.onTapGesture {
self.isSharePresented = true
}
.sheet(isPresented: $isSharePresented, onDismiss: {
print("Dismiss")
}, content: {
ActivityViewController(activityItems: ["Weather Forecast \nDay: \(daily.time[index]), \n Min temp: \(daily.temperature2MMin[index]), \n Max temp: \(daily.temperature2MMax[index])"])
//
self.dictionary[index]! += 1
print(dictionary)
})
}.padding(.horizontal, 20)
}
}.onAppear() {
WeatherService().getDate { (results) in
self.results = results
print("Api Done")
}
}
}
struct MyView_Previews: PreviewProvider {
static var previews: some View {
MyView()
}
}
struct ActivityViewController: UIViewControllerRepresentable {
var activityItems: [Any]
var applicationActivities: [UIActivity]? = nil
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController {
let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities)
print("load sheet")
return controller
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {
print("done sheet")
}
}