iPhone 4 丢失后多久会搜索一次数据服务?

发布于 2024-12-08 00:08:13 字数 239 浏览 5 评论 0原文

长期读者,第一次提问。

我正在编写一个 iPhone 应用程序,需要以某种优雅的方式处理手机进出数据覆盖范围的情况。我可以设置带有通知的可达性,以查明它何时丢失或返回,但这对我了解收音机寻找信号的频率会很有帮助 - 并且这个速度会随着时间的推移而减慢吗?另外,我可以通过编程做些什么(比如当我知道我没有覆盖范围时对服务器进行 ping 操作)来加快速度吗?

电池寿命对我来说并不是一个大问题,而且我不会通过 iTunes 进行部署。

Long time reader, first time asker.

I'm programming an iPhone application that needs to handle the phone going in and out of data coverage with some elegance. I can set up the Reachability with notifications to find out when it gets lost or comes back, but it would be helpful for me to know how often the radios are looking for a signal - and does this rate slow down over time? Also, is there anything I can do programmatically (like pinging a server when I know I don't have coverage) to speed it up?

Battery life is not really a big concern for me, and I will not be deploying through iTunes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乄_柒ぐ汐 2024-12-15 00:08:13

你想要的都是可能的。首先获取 来自 Apple 的可达性代码 。然后您需要编写一个 checkNetworkStatus 实现。这就是通知的来源 -

#import "Reachability.h"

- (void)checkNetworkStatus:(NSNotification *)notice
{
    // called after network status changes
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];

    switch(internetStatus)
    {
        case NotReachable:
        {
            self.internetActive = NO;
            break;
        }
        case ReachableViaWiFi:
        {
            self.internetActive = YES;
            break;
        }
        case ReachableViaWWAN:
        {
            self.internetActive = YES;
            break;
        }
    }

    NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
    switch (hostStatus)
    {
        case NotReachable:
        {
            self.hostActive = NO;
            break;
        }
        case ReachableViaWiFi:
        {
            self.hostActive = YES;
            break;
        }
        case ReachableViaWWAN:
        {
            self.hostActive = YES;
            break;
        }
    }
    return;
}

现在您需要开始通知 -

-(void)viewWillAppear:(BOOL)animated
{
    //NSLog(@"View Will Appeared!!");

    // check for internet connection
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(checkNetworkStatus:) 
                                                 name:kReachabilityChangedNotification 
                                               object:nil];
    internetReachable = [[Reachability reachabilityForInternetConnection] retain];
    [internetReachable startNotifier];

    // check if a pathway to a random host exists
    hostReachable = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
    [hostReachable startNotifier];

    // now patiently wait for the notification
    return;
}

What you want is possible. First off get Reachability code from Apple. Then you need to write a checkNetworkStatus implementation. This is where notifications come -

#import "Reachability.h"

- (void)checkNetworkStatus:(NSNotification *)notice
{
    // called after network status changes
    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];

    switch(internetStatus)
    {
        case NotReachable:
        {
            self.internetActive = NO;
            break;
        }
        case ReachableViaWiFi:
        {
            self.internetActive = YES;
            break;
        }
        case ReachableViaWWAN:
        {
            self.internetActive = YES;
            break;
        }
    }

    NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
    switch (hostStatus)
    {
        case NotReachable:
        {
            self.hostActive = NO;
            break;
        }
        case ReachableViaWiFi:
        {
            self.hostActive = YES;
            break;
        }
        case ReachableViaWWAN:
        {
            self.hostActive = YES;
            break;
        }
    }
    return;
}

Now you need to start your notifications -

-(void)viewWillAppear:(BOOL)animated
{
    //NSLog(@"View Will Appeared!!");

    // check for internet connection
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(checkNetworkStatus:) 
                                                 name:kReachabilityChangedNotification 
                                               object:nil];
    internetReachable = [[Reachability reachabilityForInternetConnection] retain];
    [internetReachable startNotifier];

    // check if a pathway to a random host exists
    hostReachable = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
    [hostReachable startNotifier];

    // now patiently wait for the notification
    return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文