iOS Development Basics-Fragmentation 41

Source: Internet
Author: User

1:uiwebview loading the local HTML

NSString *path =*baseurl =* Htmlpath = [[NSBundle mainbundle] Pathforresource:@ "index1< /c4>"                                                      ofType:@"html"* htmlcont = [NSString Stringwithcontentsoffile:htmlpath                                                encoding:nsutf8stringencoding                                                   error:nil];[ Self.webview Loadhtmlstring:htmlcont Baseurl:baseurl];

Note: How to create a css,js,html file within a project, create a ios-other-empty if CSS ends with. css, JS ends with. js, HTML ends with. html

The application of 2:jspatch

A:oc to Jspatch Address: http://bang590.github.io/JSPatchConvertor/

B:jspatch Script Introduction Address: Https://github.com/bang590/JSPatch/wiki

C: Relatively good Article address: ww.cnblogs.com/dsxniubility/p/5080875.html

D:jspatch Auto-fill address: Https://github.com/bang590/JSPatchX

Note Version control (can be based on the app's version number of the service side of the request address) and JS Security (MD5 encryption and then the app decryption);

Some considerations for the Central Administration:

Share a Help class below:

#import"JSPatchHelper.h"//file nameNSString *ConstJspatchjsfilename=@"Main.js"; @implementation Jspatchhelper+(instancetype) sharedinstance{Staticjspatchhelper* instance =Nil; Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{instance= [JspatchhelperNew];    }); returninstance;}+(void) hsdevaluatescript{//get the downloaded JS file locallyNsurl *p =FilePath; //determine if a file existsNSString *curfilepath=[p.path stringbyappendingstring:[nsstring stringWithFormat:@"/%@", Jspatchjsfilename]]; if(![[Nsfilemanager Defaultmanager] Fileexistsatpath:curfilepath]) {        return; }        //Get contentNSString *js =[NSString Stringwithcontentsoffile:curfilepath encoding:nsutf8stringencoding Error:nil]; //If there is content    if(Js.length >0)    {        //-------        //The service side to the JS content to encrypt, here to decrypt JS content; increased security//----                        //Run[Jpengine StartEngine];    [Jpengine Evaluatescript:js]; }}+(void) loadjspatch{//optimize the interval for a period of time to request again otherwise too often (this side is defined as one hours to go to request once)NSDate *mynowdate=[NSDate Date]; if(!bbuserdefault.mbjspatchtime) {bbuserdefault.mbjspatchtime=mynowdate; return; }    if([Mynowdate timeintervalsincedate:bbuserdefault.mbjspatchtime]<3600) {        return; }        //use afnetwork to download the JS file on the serverNsurlsessionconfiguration *configuration =[Nsurlsessionconfiguration defaultsessionconfiguration]; Afurlsessionmanager*manager =[[Afurlsessionmanager alloc] initwithsessionconfiguration:configuration]; Nsurl*url =[Nsurl Urlwithstring:kjspatchserverpath]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:url]; Nsurlsessiondownloadtask*downloadtask = [Manager downloadtaskwithrequest:request progress:nil Destination:^nsurl * (Nsurl *targetPath, Nsurlresponse *response) {Nshttpurlresponse*httpresponse = (nshttpurlresponse*) response; if(httpresponse.statuscode== $) {Nsurl*documentsdirectoryurl =FilePath; //Save to local library/caches directory                                                      return[Documentsdirectoryurl Urlbyappendingpathcomponent:jspatchjsfilename]; }                                                  Else                                                  {                                                      returnNil; }} Completionhand Ler:^ (Nsurlresponse *response, Nsurl *filepath, Nserror *error) {NSLog (@"download failed to:%@", FilePath);    }]; [Downloadtask resume];} @end

Detailed source code can be reached: Https://github.com/wujunyang/MobileProject view

3: Certificate nearing expiration issue

First step: If the developer certificate expires, first open the key center and generate a CSR (certificate request). Then, go to Apple Center and revoke the certificate, then create a new one, and the new will default to all the settings for the certificate that just revoke. Export the downloaded certificate to a copy of the p12 format (because if someone else needs it, you can only take it with you and it won't be available for download at Apple Center.) Then go to provision profile edit, new download, replace the original. You can continue to develop (no impact on users who are already installed outside).

The second step: Install the new P12 certificate, and download the modified description file, if the local already installed after the provisioning profile to be deleted first, you can enter the ~/library/mobiledevice/ Provisioning Profiles, find the appropriate file to delete, because in the file it is named after a string of words identifier, you can remove the old certificate and then packaged in Xcode, it will be prompted with this Provisioning profile name , delete it, and then install the latest provisioning profile , and select the appropriate certificate to be able ;

4: Add prefix to project new file by default

5:ios Remote push knowledge points

When our devices are networked (either cellular or wi-fi), a long connection will be established with Apple's apns Server ( persistent IP connection), when provider (our own backend server, used to push ) when pushing a notification , this notice is not directly sent to our device, but first pushed to Apple's apns server above, and Apple 1-1, figure 1-2). And when the device is in a non-networked state, apns server will retain provider the last notification pushed, when the device is converted to a network state, apns the last notification saved by the server will also be lost. remote notification must require the device to be connected to the network status to receive, and too often receive remote push notifications for the device's battery life is somewhat affected.

< Span class= "S1" > /span>

devicetoken Generation: When a app registered to receive remote notifications, the system sends a request to apns server receives this request will generate a unique key value based on the devicetoken, then apns server will be devicetoken packaged into a app. Then app this devicetoken sent to our own server, is called provider. provider received devicetoken after storage and other related processing, later provider to our device push notification, Must contain this devicetoken

Remote push content

Each notification message consists of a JSON Dictionary object in the format shown below, and the key value in the example is the official Apple key. Avoid these key values when customizing the 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: Push message must have Keyalert: Push message contains this key value, the system will display the standard push information according to the user's settings badge: Display the number of messages on the app icon, missing this key value, the number of messages will not change, When removing the tag, set the value of this key to 0sound: Set the key value of the push sound, the system default cue sound value value is Defaultcontent-available: This key value is set to 1, when the system receives a push message, it calls a different callback method, iOS7 after the background mode is configured Category:uimutableusernotificationcategory's identifier The key value of the actionable notification typeTitle: Brief description of the purpose of this push message, applicable system iOS8.2 after version body: Push content title-loc-key: function similar to title, additional function is internationalized, applicable system iOS8.2 after version title-loc-args: With title-loc-key field, applicable system iOS8.2 after version action-loc-Key: Operational notification type key value, no detailed description of Loc-key: Reference title-loc-Keyloc-args: Reference title-loc-Argslaunch-image: When you click the push message or move the event slider, the picture is displayed. If this key value is missing, the app's default boot picture is loaded.

Of course, the above key value is not the key value of each push message must be taken, you should select the required key value according to the requirements, in addition to the above system provides the key value, you can also customize your own key value, as the load of message push, custom The key value is tied to the APS this key value. The following format:

{    "APS" : {        "Alert":"Provider push Messag.",        "badge":9,        " Sound":"Toalice.aiff"    },    "Id":1314,//Custom Key value    "type":"Customtype"        //Custom Key value}

Specify the user's push

For apps that require users to sign in , the push can be specified by the user, and some users can receive the same push, but some users cannot receive it. Say this to mention another token, commonly known as usertoken,Usertoken is generally based on their own company custom rules to generate. The usertoken is generated with the user's account number plus the corresponding password. This combination of the above mentioned Devicetoken, can be done according to different users to push different messages. Devicetoken find the corresponding device and the application on the device, and the usertoken corresponds to find the user. Client in the escalation of Devicetoken, to the usertoken corresponding to the service side is Provider.

iOS Development Basics-Fragmentation 41

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.