[PHP] uses XAMPP to build a local server and then uploads data to the local server using the iOS client (four. iOS side code implementation)

Source: Internet
Author: User
Tags uikit

I. Installing XAMPP http://www.cnblogs.com/lidongxu/p/5256330.html

Two. Configure MySQL http://www.cnblogs.com/lidongxu/p/5256515.html

Three. PHP-side code writing http://www.cnblogs.com/lidongxu/p/5267727.html

Then, let's take a look at how the iOS-side code is implemented.

1. VIEWCONTRLLER.M (main Class) may use its own definition of class LoginView please go to github download source code (on the way to a star ha, thank you!!!)

////viewcontroller.m//php////Created by LDW on 16/2/25.//copyright©2016 year LDW. All Rights reserved.//#import "ViewController.h"#import "MainViewController.h"#import "Define.h"@InterfaceViewcontroller () <LoginRegisterDelegate>@property (nonatomic, strong) LoginView *loginr;@End@implementation Viewcontroller-(void) viewdidload {[Super viewdidload]; #warning 1. Create login Registration page//Login Registration class CallSELF.LOGINR = [[LoginView alloc] InitWithFrame:self.view.frame];#warning 2. Proxy Agent method can get login information and registration information_loginr.delegate =Self ; [ Self. View Addsubview:_LOGINR]; }#pragma mark-loginview delegate#warning 3. Different processing according to the meaning and value of the field represented by different background-(void) Getloginname: (NSString *) name pass: (NSString *) pass{//Call the Login authentication interface (where the Get network request is used, and the way the Post Network is requested)NSString *url = @ "http://127.0.0.1/loginGet.php"; //background Specifies that the login user name field must be a pass of the name passwordNsdictionary *dic = @{@ "name": Name, @ "Pass":Pass}; //Network request a little special.[Ldxnetwork getthephpwithurl:url Par:dic success:^(id responseobject) {//background returned in the dictionary if success corresponding value is 1 for login success        if([responseobject[@ "Success"] isequaltostring:@ "1"]) {Mainviewcontroller*MAINVC =[[Mainviewcontroller alloc] init]; MAINVC. DIC =Responseobject; [Self Presentviewcontroller: MAINVC Animated:yes Completion:Nil]; }        Else{[Self Showthealertview: Self andafterdissmiss:1.0 title:@ "account or password Error" message:@ ""]; }} Error: ^ (Nserror *error) {NSLog (@"%@",error);        }]; }-(void) Getregistername: (NSString *) name pass: (NSString *) Pass Age: (NSString *) Age Telephone: (NSString *) telephone Image: (UIImage *) image{NSString*url = @ "http://127.0.0.1/register.php"; Nsdictionary*dic = @{@ "name2": Name, @ "Pass2":p, @ "Age2": Age, @ "Telephone2":Telephone}; //The network request is a little bit special. (@ "uploadimagefile" background field)[Ldxnetwork postthephpwithurl:url par:dic image:image uploadname:@ "Uploadimagefile" success:^(ID response) {nsstring*success = response[@ "Success"]; if([Success isequaltostring:@ "1"]) {            //registration successful on behalf of[Self showthealertview:self andafterdissmiss:1.5 title:@ "registered success" message:@ ""]; //Jump back to login screen[_loginr Gotologinview]; }        Else if([Success isequaltostring:@ "-1"]) {[Self Showthealertview: Self andafterdissmiss:1.5 title:@ "account has been registered" message:@ "]; }} Error: ^ (Nserror *error) {NSLog (@"%@",error); }];}-(void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@End

2. MainViewController.h Login to the interface

// //  mainviewcontroller.h//  php////  Created by LDW on 16/3/11.//copyright©2016  year LDW. All Rights reserved.//#import <UIKit/UIKit.h>@interface Mainviewcontroller: uiviewcontroller@property (nonatomic, Strong) nsdictionary *dic;@End 

2.1 MAINVIEWCONTROLLER.M

////mainviewcontroller.m//php////Created by LDW on 16/3/11.//copyright©2016 year LDW. All Rights reserved.//#import "MainViewController.h"@InterfaceMainviewcontroller () @End@implementation Mainviewcontroller-(void) viewdidload {[Super viewdidload]; Self. View.backgroundcolor =[Uicolor Whitecolor]; Uiimageview*imagev = [[Uiimageview alloc] Initwithframe:cgrectmake (50, 100, 200, 200)]; Imagev. BackgroundColor =[Uicolor Greencolor]; //remove the header image for the user nameNSString *imagevalue = self.dic[@ "Name"]; #warning 5. Directly here for the URL path stitching, because different users to take different avatar pictures, pictures are saved in a server called Download2 folder, the picture is based on the user name plus. jpg to get theNSString *url = [NSString stringwithformat:@ "%@/%@.jpg", @ "Http://127.0.0.1/download2",Imagevalue]; //Loading pictures synchronouslyNSData *data = [NSData datawithcontentsofurl:[nsurl urlwithstring:URL]]; UIImage*image = [UIImage imagewithdata:data]; [Imagev setimage:image]; [ Self. View Addsubview:Imagev]; //loop Create label, from the request down the dictionary, take out the value of the specified field displayNsarray *arr = @[@ "name" @ "Age" @ "Telephone"];  for(int i = 0; i < 3; i++) {cgfloat offy= 320; UILabel*label = [[UILabel alloc] Initwithframe:cgrectmake (50, 250, 40)]; [ Self. View Addsubview:label]; NSString*s =Arr[i]; NSString*value = self.Dic[s]; Label. Text = [NSString stringwithformat:@ "%@:%@", S,value]; }        }-(void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}/*#pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s]    Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@End

Note: You may run into this problem when you encounter this issue failed to open stream:no such file or directory

1.

Workaround: Create a folder under the local server path folder Download2

Error 2:

Without permission we'll give permission to be haha haha

Then return to the car. Then back to Xcode re-run should be no problem!!

[PHP] uses XAMPP to build a local server and then uploads data to the local server using the iOS client (four. iOS side code implementation)

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.