Files
eqn.ios/Sources/EQNNotificationContent/NotificationViewController.m
T
Andrea Busi 4d8bbdc7ef Production version
Add to Git the current app version (the same available in the OriginalZip folder)
2020-07-24 15:33:53 +02:00

84 lines
3.3 KiB
Objective-C

//
// NotificationViewController.m
// EQNNotificationContent
//
// Created by Luca Beretta on 03/01/2019.
// Copyright © 2019 Luca Beretta. All rights reserved.
//
#import "NotificationViewController.h"
#import <UserNotifications/UserNotifications.h>
#import <UserNotificationsUI/UserNotificationsUI.h>
#import <MapKit/MapKit.h>
#import "PastquakesAnnotation.h"
#import "ReteSismicaAnnotation.h"
@interface NotificationViewController () <UNNotificationContentExtension, MKMapViewDelegate>
@property (nonatomic, strong) NSDictionary *info;
@property (nonatomic, strong) NSURLSession *session;
@end
@implementation NotificationViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any required interface initialization here.
}
-(void)didReceiveNotification:(UNNotification *)notification {
self.titolo.text = notification.request.content.title;
self.descrizione.text = notification.request.content.body;
NSDictionary *dict = notification.request.content.userInfo;
CLLocation *coordinate = [[CLLocation alloc] initWithLatitude:[dict[@"latitude"] doubleValue] longitude:[dict[@"longitude"] doubleValue]];
MKCoordinateSpan span = MKCoordinateSpanMake(10.5, 10.5);
MKCoordinateRegion region = MKCoordinateRegionMake(coordinate.coordinate, span);
self.mappa.delegate = self;
[self.mappa setCenterCoordinate:coordinate.coordinate animated:NO];
[self.mappa setRegion:region animated:YES];
self.mappa.scrollEnabled = NO;
if ([dict[@"type"] isEqualToString:@"eqn"]) {
PastquakesAnnotation *annotation = [[PastquakesAnnotation alloc] initWithTitle:notification.request.content.body location:coordinate.coordinate intensita:[dict[@"intensity"] intValue]];
[self.mappa addAnnotation:annotation];
}
else if ([dict[@"type"] isEqualToString:@"manual"]){
ReteSismicaAnnotation *annotation = [[ReteSismicaAnnotation alloc] initWithTitle:notification.request.content.body location:coordinate.coordinate magnitudo:[dict[@"magnitudo"] intValue]];
[self.mappa addAnnotation:annotation];
}
self.onda.text = [NSString stringWithFormat:@"%@ %@ %@", NSLocalizedString(@"Onda sismica in", @""), dict[@"wave_speed"], NSLocalizedString(@"secondi", @"")];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
if ([annotation isKindOfClass:[PastquakesAnnotation class]]) {
PastquakesAnnotation *anLocation = (PastquakesAnnotation *)annotation;
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:IDENTIFIER_ANNOTATION_PASTQUAKES];
if (annotationView == nil)
annotationView = anLocation.annotationView;
else
annotationView.annotation = anLocation;
return annotationView;
}
else if ([annotation isKindOfClass:[ReteSismicaAnnotation class]]) {
ReteSismicaAnnotation *anLocation = (ReteSismicaAnnotation *)annotation;
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:IDENTIFIER_ANNOTATION_RETESMARTPHONE];
if (annotationView == nil)
annotationView = anLocation.annotationView;
else
annotationView.annotation = anLocation;
return annotationView;
}
return nil;
}
@end