Permalink
Browse files

Checks internet connection before proceeding

Checks internet connection as well as availability of the appropriate
service before showing any further UI/NS Views. Shows an NSAlertPanel
or UIAlertView if internet connection is down or service can't be
reached.
  • Loading branch information...
1 parent f2bec60 commit b59cb417c90bf67c387759afc4b03f866603be3d @eternalstorms committed Jul 12, 2012
@@ -543,7 +543,7 @@
393EC2101482702000F7074A /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 0440;
ORGANIZATIONNAME = "Eternal Storms Software";
};
buildConfigurationList = 393EC2131482702000F7074A /* Build configuration list for PBXProject "ESSVideoShare" */;
@@ -677,6 +677,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
+ COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_SEARCH_PATHS = (
@@ -697,6 +698,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
+ COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_SEARCH_PATHS = (
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0430"
+ LastUpgradeVersion = "0440"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -42,6 +42,52 @@ - (void)uploadVideoAtURL:(NSURL *)videoURL
return;
}
+ NSURL *testURL = [NSURL URLWithString:@"http://www.facebook.com"];
+ NSError *err = nil;
+ NSData *dat = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:testURL] returningResponse:nil error:&err];
+
+ if (dat == nil || err != nil)
+ {
+#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
+ NSWindow *win = [NSApp mainWindow];
+ if ([self.delegate respondsToSelector:@selector(ESSFacebookNeedsWindowToAttachTo:)])
+ win = [self.delegate ESSFacebookNeedsWindowToAttachTo:self];
+ if (win != nil)
+ {
+ NSBeginAlertSheet(ESSLocalizedString(@"ESSFacebookNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil,
+ nil,
+ win, nil, nil, nil, nil,
+ ESSLocalizedString(@"ESSFacebookNoInternetConnectionMsg",nil));
+ } else
+ {
+ NSRunAlertPanel(ESSLocalizedString(@"ESSFacebookNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFacebookNoInternetConnectionMsg",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil, nil);
+ }
+#else
+ UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSFacebookNoInternetConnection",nil)
+ message:ESSLocalizedString(@"ESSFacebookNoInternetConnectionMsg",nil)
+ delegate:nil
+ cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
+ otherButtonTitles:nil];
+
+ [aV show];
+ [aV release];
+#endif
+
+ if ([self.delegate respondsToSelector:@selector(ESSFacebookDidFinish:)])
+ [self.delegate ESSFacebookDidFinish:self];
+
+ return;
+ }
+
+ dat = nil;
+ err = nil;
+ testURL = nil;
+
#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
self._fbWinCtr = [[[ESSFacebookWindowController alloc] initWithDelegate:self appID:self.appID videoURL:videoURL] autorelease];
[self._fbWinCtr loadWindow];
@@ -66,7 +66,7 @@
- (void)_deauthorize;
-- (BOOL)_canUploadVideosKeyInvalidCheck:(BOOL *)keyInvalid;
+- (BOOL)_canUploadVideosKeyInvalidCheck:(BOOL *)keyInvalid errorConnecting:(BOOL *)errorConnecting;
- (NSString *)_unescapedString:(NSString *)aString;
View
@@ -148,6 +148,52 @@ - (void)uploadVideoAtURL:(NSURL *)url
if (url == nil)
return;
+ NSURL *testURL = [NSURL URLWithString:@"http://www.flickr.com"];
+ NSError *err = nil;
+ NSData *dat = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:testURL] returningResponse:nil error:&err];
+
+ if (dat == nil || err != nil)
+ {
+#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
+ NSWindow *win = [NSApp mainWindow];
+ if ([self.delegate respondsToSelector:@selector(ESSFlickrNeedsWindowToAttachTo:)])
+ win = [self.delegate ESSFlickrNeedsWindowToAttachTo:self];
+ if (win != nil)
+ {
+ NSBeginAlertSheet(ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil,
+ nil,
+ win, nil, nil, nil, nil,
+ ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil));
+ } else
+ {
+ NSRunAlertPanel(ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil, nil);
+ }
+#else
+ UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil)
+ message:ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil)
+ delegate:nil
+ cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
+ otherButtonTitles:nil];
+
+ [aV show];
+ [aV release];
+#endif
+
+ if ([self.delegate respondsToSelector:@selector(ESSFlickrDidFinish:)])
+ [self.delegate ESSFlickrDidFinish:self];
+
+ return;
+ }
+
+ dat = nil;
+ err = nil;
+ testURL = nil;
+
//check length of video
//if longer than 90 secs, refuse and show alert
AVURLAsset *vid = [[[AVURLAsset alloc] initWithURL:url options:nil] autorelease];
@@ -221,7 +267,8 @@ - (void)uploadVideoAtURL:(NSURL *)url
if (self._authToken != nil)
{
BOOL tokenInvalid = NO;
- BOOL canUpload = [self _canUploadVideosKeyInvalidCheck:&tokenInvalid];
+ BOOL errorConnecting = NO;
+ BOOL canUpload = [self _canUploadVideosKeyInvalidCheck:&tokenInvalid errorConnecting:&errorConnecting];
if (canUpload)
{
//token valid
@@ -237,7 +284,7 @@ - (void)uploadVideoAtURL:(NSURL *)url
[self._viewCtr updateUsername:username];
[self._viewCtr switchToUploadViewWithAnimation:NO];
#endif
- } else
+ } else //canUpload == NO
{
if (tokenInvalid)
{
@@ -252,31 +299,65 @@ - (void)uploadVideoAtURL:(NSURL *)url
{
//user is over quota. dismiss and show alert sheet
#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
- if (attachWindow != nil)
+ if (!errorConnecting)
{
- NSBeginAlertSheet(ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil),
- ESSLocalizedString(@"ESSFlickrOKButton",nil),
- nil,
- nil,
- attachWindow, nil, nil, nil, nil,
- ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil));
- } else
+ if (attachWindow != nil)
+ {
+ NSBeginAlertSheet(ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil,
+ nil,
+ attachWindow, nil, nil, nil, nil,
+ ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil));
+ } else
+ {
+ NSRunAlertPanel(ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil),
+ ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil, nil);
+ }
+ } else //errorConnecting
{
- NSRunAlertPanel(ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil),
- ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil),
- ESSLocalizedString(@"ESSFlickrOKButton",nil),
- nil, nil);
+ if (attachWindow != nil)
+ {
+ NSBeginAlertSheet(ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil,
+ nil,
+ attachWindow, nil, nil, nil, nil,
+ ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil));
+ } else
+ {
+ NSRunAlertPanel(ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil, nil);
+ }
}
#else
- [currVCtr dismissViewControllerAnimated:YES completion:nil];
- UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil)
- message:ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil)
- delegate:nil
- cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
- otherButtonTitles:nil];
-
- [aV show];
- [aV release];
+ if (!errorConnecting)
+ {
+ [currVCtr dismissViewControllerAnimated:YES completion:nil];
+ UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSFlickrUserOverVideoQuota",nil)
+ message:ESSLocalizedString(@"ESSFlickrUserOverVideoQuotaMsg",nil)
+ delegate:nil
+ cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
+ otherButtonTitles:nil];
+
+ [aV show];
+ [aV release];
+ } else //errorConnecting == YES
+ {
+ [currVCtr dismissViewControllerAnimated:YES completion:nil];
+ UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSFlickrNoInternetConnection",nil)
+ message:ESSLocalizedString(@"ESSFlickrNoInternetConnectionMsg",nil)
+ delegate:nil
+ cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
+ otherButtonTitles:nil];
+
+ [aV show];
+ [aV release];
+ }
#endif
if ([self.delegate respondsToSelector:@selector(ESSFlickrDidFinish:)])
@@ -493,7 +574,7 @@ - (void)handleGetFlickrOAuthURL:(NSAppleEventDescriptor *)event withReplyEvent:(
} else
{
//auth worked
- if ([self _canUploadVideosKeyInvalidCheck:nil] == YES)
+ if ([self _canUploadVideosKeyInvalidCheck:nil errorConnecting:nil] == YES)
{
//let windowobject know about it, show upload settings
//set name
@@ -622,7 +703,7 @@ - (void)handleOpenURL:(NSURL *)url
} else
{
//auth worked
- if ([self _canUploadVideosKeyInvalidCheck:nil] == YES)
+ if ([self _canUploadVideosKeyInvalidCheck:nil errorConnecting:nil] == YES)
{
//let windowobject know about it, show upload settings
//set name
@@ -661,10 +742,12 @@ - (void)handleOpenURL:(NSURL *)url
}
#endif
-- (BOOL)_canUploadVideosKeyInvalidCheck:(BOOL *)keyInvalid
+- (BOOL)_canUploadVideosKeyInvalidCheck:(BOOL *)keyInvalid errorConnecting:(BOOL *)errorConnecting
{
if (keyInvalid)
*keyInvalid = NO;
+ if (errorConnecting)
+ *errorConnecting = NO;
if (self._authToken == nil)
return NO;
@@ -695,7 +778,10 @@ - (BOOL)_canUploadVideosKeyInvalidCheck:(BOOL *)keyInvalid
[req release];
if (err != nil || retDat == nil)
+ {
+ *errorConnecting = YES;
return NO;
+ }
NSString *str = [[[NSString alloc] initWithData:retDat encoding:NSUTF8StringEncoding] autorelease];
View
@@ -46,6 +46,52 @@ - (void)uploadVideoAtURL:(NSURL *)url
self._byteSizeOfVideo = (NSUInteger)[[[NSFileManager defaultManager] attributesOfItemAtPath:url.fileReferenceURL.path error:nil] fileSize];
self._authToken = [[[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:@"essvimeo" prefix:@"essvimeovideoupload"] autorelease];
+ NSURL *testURL = [NSURL URLWithString:@"http://www.vimeo.com"];
+ NSError *err = nil;
+ NSData *dat = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:testURL] returningResponse:nil error:&err];
+
+ if (dat == nil || err != nil)
+ {
+#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
+ NSWindow *win = [NSApp mainWindow];
+ if ([self.delegate respondsToSelector:@selector(ESSVimeoNeedsWindowToAttachWindowTo:)])
+ win = [self.delegate ESSVimeoNeedsWindowToAttachWindowTo:self];
+ if (win != nil)
+ {
+ NSBeginAlertSheet(ESSLocalizedString(@"ESSVimeoNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil,
+ nil,
+ win, nil, nil, nil, nil,
+ ESSLocalizedString(@"ESSVimeoNoInternetConnectionMsg",nil));
+ } else
+ {
+ NSRunAlertPanel(ESSLocalizedString(@"ESSVimeoNoInternetConnection",nil),
+ ESSLocalizedString(@"ESSVimeoNoInternetConnectionMsg",nil),
+ ESSLocalizedString(@"ESSFlickrOKButton",nil),
+ nil, nil);
+ }
+#else
+ UIAlertView *aV = [[UIAlertView alloc] initWithTitle:ESSLocalizedString(@"ESSVimeoNoInternetConnection",nil)
+ message:ESSLocalizedString(@"ESSVimeoNoInternetConnectionMsg",nil)
+ delegate:nil
+ cancelButtonTitle:ESSLocalizedString(@"ESSFlickrOKButton", nil)
+ otherButtonTitles:nil];
+
+ [aV show];
+ [aV release];
+#endif
+
+ if ([self.delegate respondsToSelector:@selector(ESSVimeoFinished:)])
+ [self.delegate ESSVimeoFinished:self];
+
+ return;
+ }
+
+ dat = nil;
+ err = nil;
+ testURL = nil;
+
#if (!TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR)
self._winCtr = [[[ESSVimeoWindowController alloc] initWithVideoURL:url delegate:self] autorelease];
[self._winCtr loadWindow];
@@ -98,8 +98,18 @@ - (void)resetLoginView
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- self.navigationItem.leftBarButtonItem.enabled = YES;
- self.navigationItem.rightBarButtonItem.enabled = YES;
+ UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:ESSLocalizedString(@"ESSVimeoiOSCancel", nil)
+ style:UIBarButtonItemStyleBordered
+ target:self
+ action:@selector(cancel:)];
+ self.navigationItem.leftBarButtonItem = btn;
+ [btn release];
+ btn = [[UIBarButtonItem alloc] initWithTitle:ESSLocalizedString(@"ESSVimeoiOSLogin", nil)
+ style:UIBarButtonItemStyleDone
+ target:self
+ action:@selector(login:)];
+ self.navigationItem.rightBarButtonItem = btn;
+ [btn release];
});
}
@@ -60,7 +60,7 @@
- (void)_deauthorize; //removes authorization token from userdefaults
-- (NSString *)_nameForLoggedInUser;
+- (NSString *)_nameForLoggedInUserErrorConnecting:(BOOL *)errorConnecting;
- (void)_uploadVideoAtURL:(NSURL *)url
withTitle:(NSString *)title
Oops, something went wrong.

0 comments on commit b59cb41

Please sign in to comment.