当应用程序处于后台时,它是否可能知道连接是否已从Wi-Fi切换到3G?要求是下载应在Wi-Fi连接上进行。检查最初已完成,但我需要确认下载正在使用Wi-Fi进行并且如果用户在应用程序处于后台时切换到3G/4G,则应取消下载。
当应用程序处于后台时,它是否可能知道连接是否已从Wi-Fi切换到3G?要求是下载应在Wi-Fi连接上进行。检查最初已完成,但我需要确认下载正在使用Wi-Fi进行并且如果用户在应用程序处于后台时切换到3G/4G,则应取消下载。
allowsCellularAccess
属性设置为NO
。我建议您使用这个库
它使用NSNotification,如果需要按照您的方式设置,您可以对其进行一些更改
以下是该库提供的示例代码
// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];
// Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = NO;
// Here we set up a NSNotification observer. The Reachability that caused the notification
// is passed in the object parameter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[reach startNotifier];