1 包含官方提供的m/h文件
2 包含SystemConfiguration.framework
Reachability *r = [Reachability reachabilityWithHostName:@"www.aslibra.com"];
switch ([r currentReachabilityStatus]) {
case NotReachable:
// 没有网络连接
NSLog(@"NotReachable");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Network Failed" message:@"Please check your connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil ];
[alert show];
return;
break;
case ReachableViaWWAN:
// 使用3G网络
NSLog(@"ReachableViaWWAN");
break;
case ReachableViaWiFi:
// 使用WiFi网络
NSLog(@"ReachableViaWiFi");
break;
}
//后续代码
可以参考阅读更多资料:
1 iPhone SDK: Testing Network Reachability
2 iPhone开发技巧之网络篇(4)— 确认网络环境 3G/WIFI
3 How to check for an active Internet Connection on iPhone SDK?
4 iPhone 网络连接检测(Wifi,3G,Edge),功能有点像Reachability
5 iOS/iPhone Reachability - How to only check when internet is lost/not reachable using Reachability.m/.h
6 How to check network status in iphone app?
7 如何在ios中检测网络连接
HJCache is an iOS library that makes it very easy to asynchronously load images from URLs, display them in smooth scrolling tables, and cache the images in file storage. Think about any app that loads lots of images over the net and displays them as you use the app: eg scrolling through a list of tweets or facebook posts; swiping through a photo album from a remote server. For apps like that you want the images to load asynchronously in the background so that a slow network connection doesn’t make the UI freeze. You also maybe want :
- To cache them locally so they appear faster the next time the app is used;
- The cache can trim its size;
- The images to be shared within the app, eg so that if you are looking at a list of posts by the same person, their profile pic is loaded and just once and the UIImage object is shared;
- That interrupted downloads don’t mess up the cache with incomplete images;
- That normal memory management just works, even though an object in one place may also be shared in other places, and in different parts of the cache.
- Restrict use of the network to images that are on the screen now, if for example you scroll though a long table of images, the one’s that the user scrolled past and are not off the top of the screen don’t need to be loaded.
- Allow images to finish loading to the cache in some cases, even if the views they will be used in are removed because the user went back to a previous screen right away.
- Sometimes load a few image ahead of when they are needed, eg for a swipe through photo album.
HJCache implements all this and more. (BTW, HJCache was first called HJ Object Manager, it’s the same things and the class names didn’t change.)
HJCache is free to use in free or paid iOS and Mac apps, and its been in use in one form or another since 2009 in several commercial iPhone apps made by us. For example we use it in our own app Focus for Facebook. The basis of HJCache is explained in this blog post ‘Asynchronous Image Loading in UITableView‘, but its come a long way since then.
Enumerating all the Keys and Values
Sometime, you need to iterate over all the key/value pairs in a dictionary. To do this, you use the method -allKeys to retrieve an array of all the keys in the dictionary; this array contains all the keys, in no particular (ie random) order. You can then cycle over this array, and for each key retrieve its value. The following example prints out all the key-values in a dictionary:
{
NSArray *keys;
int i, count;
id key, value;
keys = [dict allKeys];
count = [keys count];
for (i = 0; i < count; i++)
{
key = [keys objectAtIndex: i];
value = [dict objectForKey: key];
NSLog (@"Key: %@ for value: %@", key, value);
}
}
As usual, this code is just an example of how to enumerate all the entries in a dictionary; in real life, to get a description of a NSDictionary, you just do NSLog (@"%@", myDictionary);.
原文:http://www.gnustep.it/nicola/Tutorials/BasicClasses/node27.html
同时提供smtp服务给局域网其它服务器提供发送邮件服务
安装好postfix后,可以参考如下配置文件(去掉注释内容):
/etc/postfix/main.cf
mydomain = test.aslibra.com
mynetworks = 192.168.1.0/24, 127.0.0.0/8
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myorigin = $myhostname
inet_interfaces = all
unknown_local_recipient_reject_code = 550
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
PHP发送邮件可以使用phpmailer
$mail = new PHPMailer();
$mail->CharSet="UTF-8";
$mail->IsSMTP(); // 经smtp发送
$mail->Host = $this->smtp_ip; // SMTP 服务器
$mail->SMTPAuth = false; // 局域网不需要SMTP 认证
$mail->From = $from; // 发信人
$mail->FromName = $fromuser; // 发信人别名
$mail->Sender = $from;
$mail->AddAddress($to); // 收信人
if(isset($ccmail)){
$mail->AddCC($ccmail); // cc收信人
}
if(isset($bccmail)){
$mail->AddCC($bccmail); // bcc收信人
}
$mail->WordWrap = 50;
$mail->IsHTML(true); // 以html方式发送
$mail->Subject = $title; // 邮件标题
$mail->Body = $content; // 邮件内空
$mail->Send();
扩展阅读:
1 带smtp认证的postfix配置
http://hi.baidu.com/jedibd/blog/item/7b73ab25a7b7e06d35a80f45.html
2 CentOS下(PostFix)SMTP服务器的构建
http://www.fuancn.cn/html/ServerSettings/Linux/CentOS/20084288.html
3 phpmailer,smtp发送邮件实例
http://blog.51yip.com/php/910.html/comment-page-1
4 postfix邮件服务的基本配置
http://eastwalk.blogbus.com/logs/57585048.html
5 Postfix服务的基本配置
http://book.51cto.com/art/200904/118655.htm
6 telnet smtp发邮件
http://hi.baidu.com/guixiao_zhou/blog/item/49f8a73259a9f2210a55a9ec.html
7 簡易 Mail Server 架設 -- Postfix 設定
http://linux.vbird.org/linux_server/0390postfix.php
chmod 700 ~
chmod 600 ~/.ssh/authorized_keys
---------------------
一直很困惑要求输入密码,原来是不知道哪个操蛋的把root文件夹改777
drwxrwxrwx 11 root root 4096 Nov 10 22:52 root
另外一个机器被改归属人,操蛋的
drwx------ 7 mysql mysql 36864 10-26 15:03 root
参考:http://my.oschina.net/shootercn/blog/15418
SCSI硬盘还没这么便捷,但也是可以做到不重启就加入使用的。
这里关系最大的是 /proc/scsi/scsi 文件
在linux系统里, /proc 的内容是系统运行状态等信息
修改它会导致立刻生效,比如支持包转发
目前服务器在用的硬盘有两个,分别插在0和1的插槽
加入的四个硬盘分别插到3-5的插槽
IBM的机器硬盘盒的螺丝凸起的,安装到DELL的硬盘盒里,有点凸起
插入机器里会有点紧,但可以正常使用
我们先看看 /proc/scsi/scsi的文件
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: SEAGATE Model: ST3146707LC Rev: D703
Type: Direct-Access ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: SEAGATE Model: ST3146707LC Rev: D703
Type: Direct-Access ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 06 Lun: 00
Vendor: PE/PV Model: 1x6 SCSI BP Rev: 1.0
Type: Processor ANSI SCSI revision: 02
操作方法:
解释一下 scsi add-single-device a b c d 这个指令中的参数:
# 相反 scsi remove-single-device a b c d 是用来移除设备的
a ------- Host 是硬盘所在的SCSI控制器的编号,这里只有一个控制器,所以为0
b ------- Channel 硬盘所在SCSI通道的编号,这里是单通道,为0
c ------- Id 硬盘的SCSI ID号,就是插入的硬盘插槽编号,
d ------- Lun ,硬盘的lun号[logical unit number]即逻辑单元号,指的是一个用于SCSI总线的唯一的识别号,
总线使它能区别其他八个设备(它们每个都是一个逻辑单元)。
比较一下上面的内容和scsi文件的内容,我们可以知道,添加第三个插槽的硬盘是这么操作的:
[root@aslibra.com ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: SEAGATE Model: ST3146707LC Rev: D703
Type: Direct-Access ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: SEAGATE Model: ST3146707LC Rev: D703
Type: Direct-Access ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 06 Lun: 00
Vendor: PE/PV Model: 1x6 SCSI BP Rev: 1.0
Type: Processor ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: IBM-ESXS Model: MAP3147NC FN Rev: C101
Type: Direct-Access ANSI SCSI revision: 03
ifdisk -l 也可以看到此硬盘了,说明已经可以使用了
把 0 0 2 0换成0 0 3 0可以如此类似的增加余下的scsi硬盘,操作完毕!
1 本地网络故障
你如果确认可以正常访问别的网站,比如百度,新浪,那基本可以排除此故障
2 对方网站故障
ping域名,一般会解析出一个ip,如果ping不通,那可能是对方网站故障
如果网站做了防火墙规则,可能ping不到,那至少试试 telnet 域名 80 会有反应的
如果可能,把ip范围放大一些,确认该网段是否正常
3 域名解析故障
如果ping没有返回ip值,试试dig命令或者nslookup,确认是否返回ip结果
4 域名污染
部分域名被监管了,可能会强制把域名解析到无效的ip地址,比如国外的某些网站
dig可以检查一下,一般会稳定解析为某个ip一段时间,如果经常变化,那肯定是有问题了,比如脸书网
5 被封了80端口或者被重置
那。。 没辙啦
6 ip访问被封锁
那。。 也没辙啦






