1,编写通讯程序。
按照前天记录的内容,在苹果的帮助文档中找到了方法,照猫画虎即可。首要是写数据封装代码。
2,数据封装。
用NSMutableData对象即可,代码略。
3,诡异的问题。
模拟器调试不起作用,点下调试按钮后,程序运行起来,黑屏等待10s左右直接退出。但在模拟器中直接打开app可也。
手忙脚乱之时,先打开调试,同时点开gdb控制台,又能调试了,嘿。
4,将密码进行md5计算。
这个方法用extension的方法,调用时更简单:
http://stackoverflow.com/questions/1524604/md5-algorithm-in-objective-c
这是使用md5的关键代码:
http://stackoverflow.com/questions/652300/using-md5-hash-on-a-string-in-cocoa
+ (NSString*)md5HexDigest:(NSString*)input {
const char* str = [input UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret;
}