小编Mob*_*Coe的帖子

如何从iOS Reachability Class更改网络连接通知?

嗨我想捕获每当用户在我的应用程序中获得网络连接时,我已经添加了苹果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)

但在这里,当我关闭飞机模式并在手机中获得网络连接时,我没有收到任何通知.

我错过了什么吗?

objective-c reachability ios

10
推荐指数
2
解决办法
2万
查看次数

本地NSNotification消防日期需要在12小时后设置

如何在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)

任何建议表示赞赏.

objective-c nsdate nsnotificationcenter ios

-1
推荐指数
1
解决办法
639
查看次数