URL Scheme Series A----basic use

Source: Internet
Author: User

What is URL scheme and what can be done?
    • URL cheme, used between two separate apps, allows a app to open B app
    • A application opens the B app and tells B what to do with the current pass-through scheme, the required parameters
    • URL schemes is an array that allows the application to define multiple URL schemes , each of which corresponds to a different business operation

URL Scheme operation step one, according to the app to invoke the scheme and parameter format for stitching, the final open URL
/** * Generate the full scheme URL*/-(nsstring*) _genshareurl: (Xzhmessage *) msg to: (xzhtencentplatform) Shareto {nsstring*url =[[NSString alloc] initwithstring:shareschema]; NSString*boundlename =[Xzhsharemanager Base64encode:[xzhsharemanager cfbundledisplayname]; NSString*callback_name = [[Self optiondict] Objectforkey:@"Callback_name"]; Nsmutabledictionary*params= [@{                                    @"Thirdappdisplayname": Boundlename,@"version":@"1",                                    @"Cflag": [NSString stringWithFormat:@"%ld", Shareto],@"Callback_type":@"Scheme",                                    @"Generalpastboard":@"1",                                    @"Callback_name": Callback_name,@"Src_type":@"app",                                    @"Sharetype":@"0",} Mutablecopy]; //if the share message type is not set for the current message object, the news type is the default    if(Msg.link &&!)msg.messagetype) {Msg.messagetype=xzhmessagenews; } nsdictionary*subparams =Nil; if([msg computemessagetype] = =Xzhmessagetext) {NSString*filedata =[Xzhsharemanager Base64AndUrlEncode:msg.title]; Subparams= @{                      @"File_type":@"text",                      @"File_data": FileData}; } Else if([msg computemessagetype] = =xzhmessageimage) {                //Save message to clipboardNsdictionary *data=@{                             @"File_data": Msg.imagedata,@"Previewimagedata": Msg.thumbimagedata?: Msg.imagedata};                                        [[Xzhsharemanager Manager] Clipboardsave:data Forkey:saveobjectforqqplatformkey                Encoding:xzhclipboardnskeyedarchiver]; NSString*title =[Xzhsharemanager Base64AndUrlEncode:msg.title]; NSString*desc =[Xzhsharemanager Base64AndUrlEncode:msg.desc]; Subparams= @{                      @"File_type":@"img",                      @"title": Title,@"objectlocation":@"pasteboard",                      @"Description": Desc,}; }Else if([msg computemessagetype] = =xzhmessagenews) {Nsdictionary*[email protected]{@"Previewimagedata": Msg.imagedata}; //Save picture to clipboard[[Xzhsharemanager Manager] Clipboardsave:data FORKEY:SAVEOBJECTFORQQP                Latformkey Encoding:xzhclipboardnskeyedarchiver]; NSString*title =[Xzhsharemanager Base64AndUrlEncode:msg.title]; NSString*url =[Xzhsharemanager Base64AndUrlEncode:msg.link]; NSString*desc =[Xzhsharemanager Base64AndUrlEncode:msg.desc]; NSString*msgtype=@"News"; if(Msg.messagetype = =xzhmessagenews) {Msgtype=@"News"; } Else if(Msg.messagetype = =Xzhmessageaudio) {Msgtype=@"Audio"; } subparams= @{                      @"File_type": Msgtype,@"title": Title,@"URL": URL,@"Description": Desc,@"objectlocation":@"pasteboard",                      }; }        //get the last dictionary[paramsAddentriesfromdictionary:subparams]; //constructs the last scheme URLurl = [Xzhsharemanager urlstringwithoriginurlstring:url appendparameters:params]; returnURL;}

URL scheme operation Step two, using uiapplication to open this URL
+ (void) OpenURL: (NSString *) URL {    [[uiapplication sharedapplication] Openurl:[nsurl urlwithstring: URL]];}

URL scheme operation step three, the app returned by the open results, drop the callback function of our own app, Appdelegate inside the method
-(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) annotation {        // Other apps drop the current app, pass back the parameters, If the incoming URL can handle the    if  ([[[Xzhsharemanager Manager] Handleopenurl:url]        ) {return YES;    }         // apps that can't be processed are tuned up    return YES;}

URL Scheme Series A----basic use

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.