嗨我想捕获每当用户在我的应用程序中获得网络连接时,我已经添加了苹果Reachability类,下面是我在appDelegate类didFinishLaunchingWithOptions方法中使用的片段,
Reachability* reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
和我的reachabilityChanged选择器方法如下
- (void)reachabilityChanged:(NSNotification*)notification
{
Reachability* reachability = notification.object;
if(reachability.currentReachabilityStatus == NotReachable)
NSLog(@"Internet off");
else
NSLog(@"Internet on");
}
Run Code Online (Sandbox Code Playgroud)
但在这里,当我关闭飞机模式并在手机中获得网络连接时,我没有收到任何通知.
我错过了什么吗?
如何在12小时后准确设置我的localNotifications防火日期属性?我的代码片段如下,
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [NSDate date]; // how to set after 12 hours
localNotif.timeZone = [NSTimeZone defaultTimeZone];
Run Code Online (Sandbox Code Playgroud)
任何建议表示赞赏.