The main problem is that when the app is closed, there is no way to count the notifications received. Apple’s ios10 has a push extension to help users customize their push UI, so we can use this extension to do the next step in the statistics. This article focuses on how to use this extension for statistics, and the problems that may be encountered in the statistics process

1. Add extensions to the project

1. Add target

2. Select extensions

3. Fill in the extension name, for example, my notificationServer 4. Xcode automatically generates an extension file with two methods. As shown in figure

This method is called when the program receives a notification in the background. So we do buried statistics or interface data reporting in this method.

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^) (UNNotificationContent * _Nonnull)) contentHandler API_AVAILABLE (ios) (10.0)Copy the code

The second method is called when the call is about to expire.

// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
- (void)serviceExtensionTimeWillExpire 
Copy the code

Pay attention to

1. When testing, target should select the extension instead of running the main project directly.

You then rely on the main project run

2. The Bundle ID of your extension should be similar to the main project.

For example, Main project is com.com pany. Test your extension should be com.com pany. Test. NotificationServer

But don’t worry about that. When you add an extension, it’s automatically generated, you don’t have to move it.

3. Note that your extension support version number is consistent with the main project.

Otherwise you might not get the notification. Because it was created at the highest version by default. This needs to be changed.

4. This extension is used to modify rich text, so you need to add one when pushing

“Mutation-content “:1 This is marked so that your extension can receive callbacks. If it’s an aurora push, it has this field by default. The following figure

So when pushing, you can use your third party background to try.

5, buried point report

Extensions are a separate Target and can’t rely on any library they want like the main project. For example, our project uses a magic burial point that doesn’t support extensions. How does your push extension report buried data?

After contacting the customer service of Shence, the final solution was to use group to share data. Data is saved locally when push is received, and then reported when app is opened. This is the real time data will be almost.

It would be great if your burial point could rely directly on uploads.

So those are some of the little problems I’ve had. I hope my article has been helpful to you. And finally Good Luck My Baby.