我正在制作这个聊天应用程序,它与我的网络服务器上的 .php 文件一起使用,以将数据存储在 SQL 数据库中
到目前为止,这是我的代码:
#import "vtchatViewController.h"
@interface vtchatViewController ()
@end
@implementation vtchatViewController
@synthesize messageBox, messageView, Send, Refresh;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *usrName = [[NSUserDefaults standardUserDefaults] stringForKey:@"user_name"];
NSURL *url = [NSURL URLWithString:@"http://server.com/ios/messages.php"]; [messageView loadRequest:[NSURLRequest requestWithURL:url]];
}
- (IBAction)refreshButton:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://server.com/ios/messages.php"]; [messageView loadRequest:[NSURLRequest requestWithURL:url]];
}
- (IBAction)sendButton:(id)sender {
// server.com/ios/add.php?user=Username here&message=Message Her
[messageBox resignFirstResponder];
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=",usrName "&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
[messageView loadRequest:[NSURLRequest requestWithURL:add]];
messageBox.Text = @"";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
但是在“viewDidLoad”行上,我无法让它使用我的设置包中的用户名:
NSString* urlString = [[NSString stringWithFormat:@"http://server.com/ios/add.php?user=",usrName "&message=%@", messageBox.text] stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding];
NSURL *add = [NSURL URLWithString:urlString];
我收到错误“使用未声明的标识符'usrName',而且我不知道我是否确实将“usrName”正确地用于此
我只需要将数据发送到“server.com/ios/add.php?” 其中数据应采用以下格式:“user=Username here&message=Message here”
如果我只使用一个固定的用户名,我就可以正常工作,但是如上所述,我不知道如何让这个东西使用存储在我的设置文件中的用户名
提前致谢