Skip to content

Commit

Permalink
added internetConnection reachability
Browse files Browse the repository at this point in the history
Also when unreachable the text is red
  • Loading branch information
tonymillion committed Nov 17, 2014
1 parent 8c3632a commit 86489ff
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
@property (weak, nonatomic) IBOutlet UILabel * localWifinotificationLabel;


@property (weak, nonatomic) IBOutlet UILabel * internetConnectionblockLabel;
@property (weak, nonatomic) IBOutlet UILabel * internetConnectionnotificationLabel;


@end
72 changes: 70 additions & 2 deletions iOSReachabilityTestARC/iOSReachabilityTestARC/TMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ -(void)reachabilityChanged:(NSNotification*)note;

@property(strong) Reachability * googleReach;
@property(strong) Reachability * localWiFiReach;
@property(strong) Reachability * internetConnectionReach;

@end

Expand All @@ -41,6 +42,8 @@ - (void)viewDidLoad
self.notificationLabel.text = @"Not Fired Yet";
self.localWifiblockLabel.text = @"Not Fired Yet";
self.localWifinotificationLabel.text = @"Not Fired Yet";
self.internetConnectionblockLabel.text = @"Not Fired Yet";
self.internetConnectionnotificationLabel.text = @"Not Fired Yet";


[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -68,6 +71,7 @@ - (void)viewDidLoad
// this uses NSOperationQueue mainQueue
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
weakself.blockLabel.text = temp;
weakself.blockLabel.textColor = [UIColor blackColor];
}];
};

Expand All @@ -81,6 +85,7 @@ - (void)viewDidLoad
// this one uses dispatch_async they do the same thing (as above)
dispatch_async(dispatch_get_main_queue(), ^{
weakself.blockLabel.text = temp;
weakself.blockLabel.textColor = [UIColor redColor];
});
};

Expand All @@ -105,6 +110,7 @@ - (void)viewDidLoad

dispatch_async(dispatch_get_main_queue(), ^{
weakself.localWifiblockLabel.text = temp;
weakself.localWifiblockLabel.textColor = [UIColor blackColor];
});
};

Expand All @@ -115,10 +121,45 @@ - (void)viewDidLoad
NSLog(@"%@", temp);
dispatch_async(dispatch_get_main_queue(), ^{
weakself.localWifiblockLabel.text = temp;
weakself.localWifiblockLabel.textColor = [UIColor redColor];
});
};

[self.localWiFiReach startNotifier];



//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
// create a Reachability object for the internet

self.internetConnectionReach = [Reachability reachabilityForInternetConnection];

self.internetConnectionReach.reachableBlock = ^(Reachability * reachability)
{
NSString * temp = [NSString stringWithFormat:@" InternetConnection Says Reachable(%@)", reachability.currentReachabilityString];
NSLog(@"%@", temp);

dispatch_async(dispatch_get_main_queue(), ^{
weakself.internetConnectionblockLabel.text = temp;
weakself.internetConnectionblockLabel.textColor = [UIColor blackColor];
});
};

self.internetConnectionReach.unreachableBlock = ^(Reachability * reachability)
{
NSString * temp = [NSString stringWithFormat:@"InternetConnection Block Says Unreachable(%@)", reachability.currentReachabilityString];

NSLog(@"%@", temp);
dispatch_async(dispatch_get_main_queue(), ^{
weakself.internetConnectionblockLabel.text = temp;
weakself.internetConnectionblockLabel.textColor = [UIColor redColor];
});
};

[self.internetConnectionReach startNotifier];

}

- (void)viewDidUnload
Expand Down Expand Up @@ -163,14 +204,18 @@ -(void)reachabilityChanged:(NSNotification*)note
if([reach isReachable])
{
NSString * temp = [NSString stringWithFormat:@"GOOGLE Notification Says Reachable(%@)", reach.currentReachabilityString];
self.notificationLabel.text = temp;
NSLog(@"%@", temp);

self.notificationLabel.text = temp;
self.notificationLabel.textColor = [UIColor blackColor];
}
else
{
NSString * temp = [NSString stringWithFormat:@"GOOGLE Notification Says Unreachable(%@)", reach.currentReachabilityString];
self.notificationLabel.text = temp;
NSLog(@"temp");

self.notificationLabel.text = temp;
self.notificationLabel.textColor = [UIColor redColor];
}
}
else if (reach == self.localWiFiReach)
Expand All @@ -179,16 +224,39 @@ -(void)reachabilityChanged:(NSNotification*)note
{
NSString * temp = [NSString stringWithFormat:@"LocalWIFI Notification Says Reachable(%@)", reach.currentReachabilityString];
NSLog(@"%@", temp);

self.localWifinotificationLabel.text = temp;
self.localWifinotificationLabel.textColor = [UIColor blackColor];
}
else
{
NSString * temp = [NSString stringWithFormat:@"LocalWIFI Notification Says Unreachable(%@)", reach.currentReachabilityString];
NSLog(@"%@", temp);

self.localWifinotificationLabel.text = temp;
self.localWifinotificationLabel.textColor = [UIColor redColor];
}
}
else if (reach == self.internetConnectionReach)
{
if([reach isReachable])
{
NSString * temp = [NSString stringWithFormat:@"InternetConnection Notification Says Reachable(%@)", reach.currentReachabilityString];
NSLog(@"%@", temp);

self.internetConnectionnotificationLabel.text = temp;
self.internetConnectionnotificationLabel.textColor = [UIColor blackColor];
}
else
{
NSString * temp = [NSString stringWithFormat:@"InternetConnection Notification Says Unreachable(%@)", reach.currentReachabilityString];
NSLog(@"%@", temp);

self.internetConnectionnotificationLabel.text = temp;
self.internetConnectionnotificationLabel.textColor = [UIColor redColor];
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<string key="NSFrame">{{20, 217}, {280, 21}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="NSNextKeyView" ref="989414663"/>
<string key="NSHuggingPriority">{251, 251}</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUIContentMode">7</int>
Expand All @@ -136,6 +136,50 @@
<reference key="IBUIFont" ref="526681277"/>
<bool key="useAutomaticPreferredMaxLayoutWidth">YES</bool>
</object>
<object class="IBUILabel" id="989414663">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 307}, {280, 21}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="18039245"/>
<string key="NSHuggingPriority">{251, 251}</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">internet connection Block</string>
<reference key="IBUITextColor" ref="930458148"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<float key="IBUIMinimumFontSize">10</float>
<int key="IBUITextAlignment">1</int>
<reference key="IBUIFontDescription" ref="1009593852"/>
<reference key="IBUIFont" ref="526681277"/>
<bool key="useAutomaticPreferredMaxLayoutWidth">YES</bool>
</object>
<object class="IBUILabel" id="18039245">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 336}, {280, 21}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSHuggingPriority">{251, 251}</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUIContentMode">7</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">internet connection Notification</string>
<reference key="IBUITextColor" ref="930458148"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<float key="IBUIMinimumFontSize">10</float>
<int key="IBUITextAlignment">1</int>
<reference key="IBUIFontDescription" ref="1009593852"/>
<reference key="IBUIFont" ref="526681277"/>
<bool key="useAutomaticPreferredMaxLayoutWidth">YES</bool>
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
Expand Down Expand Up @@ -199,6 +243,22 @@
</object>
<int key="connectionID">15</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">internetConnectionblockLabel</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="989414663"/>
</object>
<int key="connectionID">19</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">internetConnectionnotificationLabel</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="18039245"/>
</object>
<int key="connectionID">20</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand Down Expand Up @@ -227,6 +287,8 @@
<reference ref="397288832"/>
<reference ref="191091809"/>
<reference ref="607828031"/>
<reference ref="989414663"/>
<reference ref="18039245"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -250,6 +312,16 @@
<reference key="object" ref="607828031"/>
<reference key="parent" ref="774585933"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">17</int>
<reference key="object" ref="989414663"/>
<reference key="parent" ref="774585933"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">18</int>
<reference key="object" ref="18039245"/>
<reference key="parent" ref="774585933"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -259,8 +331,10 @@
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="12.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="17.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="18.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<reference key="6.IBNSViewMetadataGestureRecognizers" ref="0"/>
<string key="6.IBPersistedLastKnownCanvasPosition">{227, 341}</string>
<string key="6.IBPersistedLastKnownCanvasPosition">{20, 336}</string>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
Expand All @@ -269,7 +343,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">15</int>
<int key="maxID">20</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -278,6 +352,8 @@
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="blockLabel">UILabel</string>
<string key="internetConnectionblockLabel">UILabel</string>
<string key="internetConnectionnotificationLabel">UILabel</string>
<string key="localWifiblockLabel">UILabel</string>
<string key="localWifinotificationLabel">UILabel</string>
<string key="notificationLabel">UILabel</string>
Expand All @@ -287,6 +363,14 @@
<string key="name">blockLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="internetConnectionblockLabel">
<string key="name">internetConnectionblockLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="internetConnectionnotificationLabel">
<string key="name">internetConnectionnotificationLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="localWifiblockLabel">
<string key="name">localWifiblockLabel</string>
<string key="candidateClassName">UILabel</string>
Expand Down

0 comments on commit 86489ff

Please sign in to comment.