Вам не нужен экземпляр ресурсов. Вы можете использовать строковый ресурс, как вы сделали для рисования:
private enum class Item(
val id: Int,
@DrawableRes val imageRes: Int,
@StringRes val title: Int
)
I included Apple's Reachability.h & .m from their Reachability example, plus the SystemConfiguration framework mentioned above, and then added the following code to my app, which has two advantages over the above answer - it gives you more information, and you get asynchronous notifications of network status changes.
In your app delegate, or similar, add this when you start up:
[self startReachability];
Then add this method, which gets called when the network changes:
#pragma mark Reachability changed
- (void)reachabilityChanged:(NSNotification*)aNote
{
self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
switch (self.remoteHostStatus)
{
case NotReachable:
debugForComponent(kDebugMaskApp,@"Status changed - host not reachable");
break;
case ReachableViaCarrierDataNetwork:
debugForComponent(kDebugMaskApp,@"Status changed - host reachable via carrier");
break;
case ReachableViaWiFiNetwork:
debugForComponent(kDebugMaskApp,@"Status changed - host reachable via wifi");
break;
default:
debugForComponent(kDebugMaskApp,@"Status changed - some new network status");
break;
}
}
I figured it out after breaking XCode once trying to copy the SystemConfiguration.framework in... Here's the solution for anyone who may be interested...
Add the SystemConfiguration.framework to your project, do an #import
SCNetworkReachabilityFlags flags;
BOOL receivedFlags;
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"google.com" UTF8String]);
receivedFlags = SCNetworkReachabilityGetFlags(reachability, &flags);
CFRelease(reachability);
if (!receivedFlags || (flags == 0) )
{
// internet not available
} else {
// internet available
}
Well, hope this helps someone anyway... Seems like a common way to have an app rejected...
Моей первой идеей было бы посмотреть, смогу ли я подключиться к Google.
Ссылка на пример достижимости;
http://developer.apple.com/iphone/library/samplecode/Reachability/index.html
Это самое быстрое и простое решение вашей проблемы:
([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]]!=NULL)?YES:NO;
Он вернет ДА
, если он подключен, или НЕТ
, если нет. Он просто пытается загрузить Google, и в случае успеха возвращает YES
.
Затем у вас может быть оператор if
с возвращаемым значением, чтобы вы могли выдавать уведомление или что угодно.