English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Remote push notifications
What are remote push notifications
As the name implies, it is a notification pushed from the remote server to the client (requires internet connection). Remote push service is also known as APNs (Apple Push Notification Services)
Why do we need remote push notifications
Limitations of traditional data acquisition: if the user closes the app, it is impossible to communicate with the app's server and cannot obtain the latest data content from the server
Remote push notifications can solve the above problems. Whether the user opens or closes the app, as long as the internet is connected, they can receive remote notifications pushed by the server
Instructions for using remote push notifications
Push Principle
Provider is our company's server, which finds our devices through Apple's APNs server and pushes messages to the client applications on our devices. How does the APNs server find our devices and the applications on them? The answer is DeviceToken. DeviceToken needs to be configured with a push certificate to obtain it, and the push certificate requires knowledge of our APP ID (the BundleID of the application, the unique identifier of the application) and UDID (the unique identifier of the device), as well as the UDID of our own server. Let's first create a push certificate, log in to the developer center, and click on the certificate module.
Click the iOS Apps certificate
Enter the following interface
Click App IDs, then click the plus sign in the upper right corner
The arrow points to the application ID description, we assume we have written a very cool application, ExcitedApp, and then we fill in the App ID, note that the App ID here is fixed and cannot contain asterisks
Next, we add the services required by the App and then click Continue
Click Next all the way, complete, find our ExcitedApp in the App IDs list, and we see
Find that the Push service is yellow warning, at this time click Edit, find the push module, we need to configure the push certificate, click the location indicated by the red arrow
We need a CSR file, CSR is a certificate signing request file, which means that our MAC has the permission to debug push notifications, click Continue
Click Continue and we see
Then we open the Keychain on the Mac and request a certificate from the certificate authority
The first two can be written arbitrarily, and finally choose to save to disk
After completing, next we can add the CSR file
After adding, select Generate
The certificate is configured, download it
Configured!
By the way, we also configure the release certificate, the steps are the same
Open the certificate we just downloaded and add it to the keychain
Finally, we can start working on our project, I almost cried
Don't forget to modify the bundle ID, and you also need to create a real device debugging certificate
The debugging on real devices is not elaborated here, after doing all this, we finally get the DeviceToken
Register push notifications in AppDelegate.m
- (BOOL)application:(UIApplication *application didFinishLaunchingWithOptions:(NSDictionary *} UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert ; UIUserNotificationSettings * setting = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:setting]; return YES; } -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"%@",deviceToken); }
DeviceToken Handling Process
Next, let's test our push with PushMebaby: https://github.com/stefanhafeneger/PushMeBaby/
Add our push certificate to the project directory
You can receive push notifications on your phone next.
This article has been organized into 'iOS Push Tutorial', welcome to study and read.
That's all for this article. I hope it will be helpful to everyone's learning, and I also hope everyone will support the Yelling Tutorial more.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously, and this website does not own the copyright, has not been manually edited, and does not assume any relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending email) to report any violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.