After the release of IOS10, the book first developed a new notice to increase the iOS10. This article shares the problems encountered during the development of the entire feature.
1. Project configuration
Xcode8 has changed a lot, directly open the original project compile run, this time is not get the push token, print didFailToRegisterForRemoteNotificationsWithError
error can see
Fail to register with error error Domain=nscocoaerrordomain code=3000 "No valid ' aps-environment ' entitlement string found For application "userinfo={nslocalizeddescription=no valid ' aps-environment ' entitlement string found for application}
Google understands that it is a Xcode8 change, entitlements
configured by the local entitlements file, under the capabilities of the main target, Push Notification
in a closed state and must be opened manually.
2. Code Sign
Project added Notification Content
and Notification Service
two extension, Signing
default is Auto mode.
According to the online introduction Xcode8 signature management method than Xcode7 more intelligent, then I will try it. When you finish selecting a team, it automatically generates an authorization file. However, Xcode8 also helped me generate a new certificate, equivalent to the addition of a developer, that is, my current certificate is not in the original authorization file, the result is the original manually configured authorization file to regenerate.
Certificates
In this case, if you want to use the original manual configuration, not only to Automatically manage signing
remove, but also to Key Chains
delete the newly generated certificate, and then generate the authorization file on the Web side. It Automatically manage signing
is best to use each target in the same way.
3. Swift version
If you developed the language when you created the target, the default is to use Swift3.0,xcode8 to support both 3.0 and 2.3, you may not have come and mastered 3.0 of the API changes, you want to continue to use the 2.3 API, as long as the corresponding target Build Setting
Use Legacy Swift Language Version
set to Yes to continue using 2.3.
4, architectures
After the project is well-equipped, only the template code, first run up and write a Hello World
say. Command+R
after that, compile an error
Check Dependenciesno architectures to compile for (Only_active_arch=yes, ACTIVE arch=x86_64, valid_archs=i386).
VALID_ARCHS
There is no correspondence in theactive arch
You need to add the corresponding target in the Build Setting
Valid Architectures
arm64
ARCHITECTURES5, Notification Service
Next, the code is written, most of it is reference to the refactoring of this article of the Meow-IOS usernotifications Framework parsing and demo, as well as WWDC 708 advanced notifications, PDF.
In the service, we will download the images from the back-end push data to the local folder and then act as attachments.
Our push was preceded by a single alert, but the push JSON data alert field could be either a string or a dictionary, or a string, equivalent body
to dictionary, After iOS8.2, dictionary can be added title
, and subtitle
so on. In order to let push more rich, we want to turn the original body
into title
, add the article summary put in body
, if directly change aps
inside alert
, then 8.2 before the device push display is the article summary. Then we thought of a way, Notification Service
can not modify the content of the push? aps
alert
or remains the same, JSON adds a new title
and body
, after the service receives the notification, it assigns and takes title
out the JSON body
bestAttemptContent
title
body
.
{" APs": { "alert": "Test Test", "mutable-content": 1 }, "title": "New title", "body": "New Body"}
6. Notification Content
If the notification has attachments, by default long by the notification will show the picture or video, but we think that the display of a large picture is not beautiful, and to have action button, is the following effect, so use Notification Content
.
Effect
In fact, there is no custom notification UI, but it hides the view directly. Info.plist
UNNotificationExtensionInitialContentSizeRatio
indicates the initial height/width (other property reference WWDC) of the view, set it to 0.001 (cannot be set to 0), and in the viewDidload
settings self.preferredContentSize = CGSizeZero;
to hide the view.
Info.plist
This extension can respond to multiple category
, and each category
can register its own action buttons, so action buttons and customUI view are independent of each other, but can be through the action Buttons Update customUI view.
Action buttons The default behavior will open the app, processed by the delegate response, Notification Content
after use, we can Notification Content
directly process the response without opening the app, or forward to open the app by delegate processing.
5, the Real machine debugging
The code is pretty much written, so it's starting to debug. Extension errors are sometimes encountered during debugging Could not attach to process ID
.
Could not attach to process ID
Sometimes restart Xcode can solve, sometimes can not solve, this time there is a method, the window pops up after the point OK
, and then point Debug > Attach to Process > 你的Extension
, then you can catch breakpoints.
6. Submit TestFlight
The test was prepared to commit the testflight, the results of validation error.
Application Loader
The error message is obvious, and the Frameworks folder is included in the Extension.appex. If extension uses Cocoapods,cocoapods to create this folder, it doesn't really work. The solution is to Build Phases
add one at a time Build Phase
and execute a shell script to erase the frameworks folder.
CD "${configuration_build_dir}/${unlocalized_resources_folder_path}/" if [[-d ' frameworks "]]; THENRM-FR FRAMEWORKSFI
Article transferred from Zhao0 's Pinterest
XCODE8 Development IOS10 Push Notification process