相关疑难解决方法(0)

如何使用Reachability类来检测网络状态?

我正在创建一个需要互联网的应用程序.我想在我的项目中使用可达性类,我想检测用户是否没有互联网连接,无论技术是wifi,Cellular.我想要一步一步的指导.

network-programming objective-c iphone-sdk-3.0 reachability

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

在iOS应用程序中实现Reachability(无Internet弹出)的最简单方法是什么?

可能重复:
如何在iPhone SDK上检查活动的Internet连接?

在iOS应用程序中实现Reachability(通知用户没有Internet连接的代码)的最简单方法是什么?

xcode ios

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

检查互联网连接和连接类型?

我想检查一下:

A - 是否有互联网连接.B - 如果有,无论是否超过wifi.

我怎样才能做到这一点?

iphone connection objective-c ios

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

如何在ios中检查互联网连接?

如何检查应用程序是否已连接到互联网?目前,我在我的appdelegate.m文件中使用此代码

dispatch_queue_t connectivityThread = dispatch_queue_create("com.gm.kart.connectivity", NULL);

dispatch_async(connectivityThread, ^{
    while (true){
        if([GMMConnectivity hasConnectivity])
            NSLog(@"%@", @"connected");
        else
            NSLog(@"Not connected");

        usleep(10000000);
    }
});
Run Code Online (Sandbox Code Playgroud)

当我点击我的登录按钮时,我想检查互联网是否已连接NSnotificationcenter

请帮我

notifications objective-c nsnotificationcenter ios

0
推荐指数
1
解决办法
1万
查看次数

当应用程序没有互联网时UIAlertView

我有一个应用程序,如果它无法访问互联网,无法加载任何东西.在我的app委托中,我使用以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    //Check for internet
    internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];

    // Internet is not reachable
    internetReachableFoo.unreachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is an example alert!" delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:nil];
        alert.alertViewStyle = UIAlertViewStylePlainTextInput;
        [alert show];
        exit(0);
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Someone broke the internet :(");

        });
    };
    [internetReachableFoo startNotifier];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

对互联网的检查是从这个响应做链接,然后我要显示一个警告框,告诉用户它没有互联网不会工作,然后关闭应用程序.目前我有exit(0);这我知道,苹果不会因此接受我的警报视图,我需要确定按钮以关闭该应用程序(如果苹果允许).我的问题是我不知道如何关闭应用程序,尤其是使用UIAlert视图(我对iOS很新),如果是显示警报视图的情况,我希望应用程序在警报视图时停止加载其他所有内容如果它没有互联网就会起来因为应用程序无论如何都会崩溃(再次,如果苹果允许你停止继续加载应用程序)我怎样才能以苹果批准的方式解决这个问题?

objective-c ios

0
推荐指数
1
解决办法
523
查看次数

检查 Internet 访问是否可用

在我的应用程序中,我只想在可以访问互联网的情况下拨打网络电话。

注意:我连接到没有互联网的 WiFi 点

我想测试互联网是否可用。我尝试使用这里描述的可达性,我也尝试了一个更简单的解决方案,如这里描述

问题在于 Reachability 会返回 Internet 可达的信息,而当它不可达时。另一种解决方案需要太多时间才能做出响应。我试图为请求和会话设置超时间隔,但它被忽略了。

如果我连接到没有互联网的 wifi,如何测试互联网可达性?

这是我使用的一些代码:

- (void) postAsyncTaskWithUrl:(NSString*)urlString
                      andType:(NSString*)requestType
                     andToken:(NSString*)token
          andPropertiesObject:(id)propObject
                   urlEncoded:(BOOL)isUrlEncoded
                  withSuccess:(nullable void(^)(id _Nullable))success
                   andFailure:(nullable void(^)(id _Nullable))failure
{

    internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];

    __weak typeof(self) weakSelf = self;
    // Internet is reachable
    internetReachableFoo.reachableBlock = ^(Reachability*reach)
    {
                 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlSt];
        [request setTimeoutInterval:20]; //Ignored ... WHY?

        NSURLSessionConfiguration *sessionConfigurations = [NSURLSessionConfiguration defaultSessionConfiguration];
        [sessionConfigurations setTimeoutIntervalForRequest:20]; //Ignored ... WHY?
        [sessionConfigurations setTimeoutIntervalForResource:20]; //Ignored ... WHY?
//        NSURLSession *session = [NSURLSession sharedSession]; …
Run Code Online (Sandbox Code Playgroud)

nsurlrequest reachability ios nsurlsession nsurlsessionconfiguration

0
推荐指数
1
解决办法
394
查看次数