UILocalNotification is obsolete in IOS10

0

I am working on an app that generates notifications, however when generating a notification on a device with a version equal to or greater than 10; the notification is not generated. How can I change the following method to work on all devices?

  - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
 {
     //mi procreso de notificaciones
 if (MOCA.initialized)
    {
        [MOCA handleLocalNotification:notification];
    }
 }
    
asked by Daniel ORTIZ 24.01.2017 в 21:29
source

1 answer

2

Several things to keep in mind:

  • If you want to work with PUSH notifications of an APNS , the delegate method you are using is not the correct one.

  • If what you want are local notifications, in iOS 10 , the UILocalNotification library is obsolete. The UserNotifications library is used. Below I leave a code that schedules a user notification. It approaches or moves away from a specific geographical point, I hope it serves as a reference. When I schedule this notification, it is displayed and the method you comment on your question is launched.

    func createLocationNotifation(
        title: String,
        text: String,
        location: CLLocation,
        identifier: String,
        onExit: Bool
    ) {
        let coordinate = CLLocationCoordinate2DMake(
            location.coordinate.latitude,
            location.coordinate.longitude
        )
        let region = CLCircularRegion(
            center: coordinate,
            radius: 100.0,
            identifier: identifier
        )
        region.notifyOnExit = onExit
        region.notifyOnEntry = !onExit
    
        let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
    
        let content = UNMutableNotificationContent()
        content.title = title
        content.body = text
        content.sound = UNNotificationSound.default()
        content.badge = 1
    
        let request = UNNotificationRequest(
            identifier: identifier,
            content: content,
            trigger: trigger
        )
        let center = UNUserNotificationCenter.current()
        center.add(request, withCompletionHandler: nil)
    }
    
  • answered by 26.01.2017 / 16:43
    source