Basic knowledge of IOS development-fragment 41 and basic knowledge of ios-41

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 41 and basic knowledge of ios-41

1: UIWebView loads the local HTML

NSString *path = [[NSBundle mainBundle] bundlePath];NSURL *baseURL = [NSURL fileURLWithPath:path];NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"index1"                                                      ofType:@"html"];NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath                                                encoding:NSUTF8StringEncoding                                                   error:nil];[self.webView loadHTMLString:htmlCont baseURL:baseURL];

Note: How to Create Css, js, and html files in the project and create iOS-other-Empty. If Css ends with .css, js ends with .js, and html ends with .html.

 

2: Use of JSPatch

Address of a: OC to JSPatch: http://bang590.github.io/JSPatchConvertor/

B: JSPatch script introduction address: https://github.com/bang590/JSPatch/wiki

C: Good article address: ww.cnblogs.com/dsxniubility/p/5080875.html

D: JSPatch auto address: https://github.com/bang590/JSPatchX

Pay attention to Version Control (the request address of the server can be supported based on the APP version number) and JS Security (MD5 encryption and APP decryption );

Management Center considerations:

The following is a help class:

# Import "JSPatchHelper. h "// file name NSString * const jsPatchJsFileName = @" main. js "; @ implementation worker + (instancetype) sharedInstance {static JSPatchHelper * instance = nil; static extends onceToken; dispatch_once (& onceToken, ^ {instance = [JSPatchHelper new];}); return instance;} + (void) HSDevaluateScript {// obtain the downloaded JS file NSURL * p = FilePath from the local device; // determine whether the file exists NSString * curFilePath = [p. path string ByAppendingString: [NSString stringWithFormat: @ "/% @", jsPatchJsFileName]; if (! [[NSFileManager defaultManager] fileExistsAtPath: curFilePath]) {return;} // obtain the content NSString * js = [NSString stringWithContentsOfFile: curFilePath encoding: NSUTF8StringEncoding error: nil]; // if there is content such as if (js. length> 0) {// ------- // The server must encrypt the JS content and decrypt the js content here; increase security // ---- // run [JPEngine startEngine]; [JPEngine evaluateScript: js] ;}+ (void) loadJSPatch {// The request is requested again after an optimization interval. Otherwise, the request is too frequent (this is defined as an hour before it is requested) NSDate * myNowDa Te = [NSDate date]; if (! BBUserDefault. MBJsPatchTime) {BBUserDefault. MBJsPatchTime = myNowDate; return;} if ([myNowDate timeIntervalSinceDate: BBUserDefault. MBJsPatchTime] <3600) {return;} // use AFNetWork to download the NSURLSessionConfiguration * configuration = [NSURLSessionConfiguration defaultSessionConfiguration] from the server. AFURLSessionManager * manager = [[AFURLSessionManager alloc] callback: configuration]; NSURL * URL = [NSURL URLWithString: kJSPatchServerPath]; NSURLRequest * request = [NSURLRequest requestWithURL: URL]; optional * downloadTask = [manager downloadTaskWithRequest: request progress: nil destination: ^ NSURL * (NSURL * targetPath, NSURLResponse * response) {NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response; if (httpResponse. statusCode = 200) {NSURL * documentsDirectoryURL = FilePath; // save it to the return [documentsDirectoryURL scheme: jsPatchJsFileName] under the local Library/Caches directory;} else {return nil;} completionHandler: ^ (NSURLResponse * response, NSURL * filePath, NSError * error) {NSLog (@ "Download failed to: % @", filePath) ;}]; [downloadTask resume];} @ end

For detailed source code, go to https://github.com/wujunyang/mobileproject.

 

3: Certificate is about to expire

Step 1: If the developer certificate expires, first open the key center and generate a CSR (certificate request ). Then, go to the Apple Center to revoke the certificate and create a new one. The new one will be set by default for all the certificates of the previous revoke. Export the downloaded certificate to a p12 format and save it (because you can only take the downloaded certificate from the Apple Center if needed .) Then go to provision profile edit and download the new one and replace the original one. You can continue the development (it will not affect the users installed on the outside ).

 

Step 2: install the new p12 certificate and download the modified description file. If you want to delete the locally installed provisioning profile, go ~ /Library/MobileDevice/Provisioning Profiles, find the corresponding file to delete, because it is named after a string of characters in the file, you can delete the old certificate first and then package it in Xcode, it will prompt the name of the provisioning profile. You can delete it. Then, install the latest provisioning profile and select the corresponding certificate;

 

 

4: Add a prefix to all new files in the project by default.

5: knowledge points for iOS remote push

When our devices are connected to the Internet (whether cellular or Wi-Fi), they will establish a persistent connection (persistent IP connection) with Apple's APNs server ), when the Provider (our own backend server for pushing) pushes a notification, this notification is not directly pushed to our device, but first pushed to Apple's APNs server, apple's APNs server then pushes notifications to our devices through persistent connections (see Figure 1-1, Figure 1-2 ). When the device is not connected to the Internet, the APNs server retains the last notification pushed by the Provider. when the device is switched to the connected network status, APNs pushes the last retained notification to the device. If the device is offline for a long time, the last notification saved by the APNs server will also be lost. Remote Notification must be received only when the device is connected to the network, and receiving Remote push notifications too frequently affects the battery life of the device.

DeviceToken generation: When an App registers to receive remote notifications, the system sends a request to the APNs server, when the APNs server receives this request, it will generate a unique value based on the key value of the request, that is, the so-called deviceToken, the APNs server then packs the deviceToken into an NSData object and sends it to the App of the corresponding request. Then the App sends the deviceToken to our own server, which is the so-called Provider. After receiving the deviceToken, the Provider will perform storage and other related processing. When the Provider pushes notifications to our devices, this deviceToken must be included.

Push content remotely

Each notification message is a JSON dictionary object in the following format. The key value in this example is the official key used by Apple. Avoid these key values when customizing fields.

{"Aps": {"alert": {// string or dictionary "title": "string" "body": "string", "title-loc-key ": "string or null" "title-loc-args": "array of strings or null" "action-loc-key": "string or null" "loc-key ": "string" "loc-args": "array of strings" "launch-image": "string"}, "badge": number, "sound ": "string" "content-available": number; "category": "string" },} aps: The keyalert required for pushing messages: Push cancel The system displays the standard push information based on user settings. badge: the number of messages displayed on the app icon. If this key value is missing, the number of messages will not change, when the tag is removed, set the value corresponding to this key to 0 sound: Set the key value of the push sound. By default, the system prompts that the value of the sound is defacontent content-available: this key value is set to 1. When the system receives the PUSH message, it will call different callback methods. After iOS7, configure the background mode category: UIMutableUserNotificationCategory's identifier to operate on the key value of the Notification Type title: A brief description of the purpose of pushing messages. Applicable to system Versions later than iOS8.2, body: Pushed content title-loc-key: features similar to title, and additional features are internationalized, applicable to system versions after iOS8.2: title-loc-args: used with the title-loc-key field, applicable to systems after iOS8.2 Version action-loc-key: indicates the value of the key that can be used to operate the notification type. For details, see loc-key: Refer to title-loc-keyloc-args: Refer to title-loc-argslaunch-image: the image displayed when you click the PUSH message or move the event slider. If this key value is missing, the default startup image of the app is loaded.

Of course, the above key value is not a key value required for each push message. You should select the key value as required, except for the key value provided by the above system, you can also customize your own key value as the load for message pushing. The custom key value is in parallel with the aps key value. The format is as follows:

{"Aps": {"alert": "Provider push mescript. "," badge ": 9," sound ":" toAlice. aiff "}," Id ": 1314, // custom key value" type ":" mtmtype "// custom key value}

Push of specified user

For apps requiring users to log on, the push can be designated users. Some users can receive the same push, but some users cannot receive it. In this case, we need to mention another token, which is generally referred to as userToken. userToken is generally generated according to the custom rules of our company. UserToken is generated by adding the corresponding password to the user's account. In this way, with the deviceToken mentioned above, different messages can be pushed to different users. DeviceToken finds the corresponding device and the application on the device, while userToken finds the user. When the client reports the deviceToken, it must report the userToken to the server, that is, the Provider.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.