Periodically ip update
This commit is contained in:
parent
dd83115850
commit
29118b03ac
@ -18,6 +18,8 @@
|
|||||||
ECE5813B181A77090066D073 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECE5811A181A77090066D073 /* Cocoa.framework */; };
|
ECE5813B181A77090066D073 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECE5811A181A77090066D073 /* Cocoa.framework */; };
|
||||||
ECE58143181A77090066D073 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = ECE58141181A77090066D073 /* InfoPlist.strings */; };
|
ECE58143181A77090066D073 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = ECE58141181A77090066D073 /* InfoPlist.strings */; };
|
||||||
ECE58145181A77090066D073 /* ipbc_ClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ECE58144181A77090066D073 /* ipbc_ClientTests.m */; };
|
ECE58145181A77090066D073 /* ipbc_ClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ECE58144181A77090066D073 /* ipbc_ClientTests.m */; };
|
||||||
|
ECE6FED6181E8AFE004F6C1F /* WebserviceClient.m in Sources */ = {isa = PBXBuildFile; fileRef = ECE6FED5181E8AFD004F6C1F /* WebserviceClient.m */; };
|
||||||
|
ECE6FEDA181E8BE4004F6C1F /* WebServiceConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = ECE6FED9181E8BE4004F6C1F /* WebServiceConstants.m */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@ -50,6 +52,10 @@
|
|||||||
ECE58140181A77090066D073 /* ipbc-ClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ipbc-ClientTests-Info.plist"; sourceTree = "<group>"; };
|
ECE58140181A77090066D073 /* ipbc-ClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ipbc-ClientTests-Info.plist"; sourceTree = "<group>"; };
|
||||||
ECE58142181A77090066D073 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
ECE58142181A77090066D073 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||||
ECE58144181A77090066D073 /* ipbc_ClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ipbc_ClientTests.m; sourceTree = "<group>"; };
|
ECE58144181A77090066D073 /* ipbc_ClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ipbc_ClientTests.m; sourceTree = "<group>"; };
|
||||||
|
ECE6FED4181E8AFD004F6C1F /* WebserviceClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebserviceClient.h; sourceTree = "<group>"; };
|
||||||
|
ECE6FED5181E8AFD004F6C1F /* WebserviceClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebserviceClient.m; sourceTree = "<group>"; };
|
||||||
|
ECE6FED8181E8BE4004F6C1F /* WebServiceConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebServiceConstants.h; sourceTree = "<group>"; };
|
||||||
|
ECE6FED9181E8BE4004F6C1F /* WebServiceConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebServiceConstants.m; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -115,6 +121,7 @@
|
|||||||
ECE58120181A77090066D073 /* ipbc-Client */ = {
|
ECE58120181A77090066D073 /* ipbc-Client */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
ECE6FED7181E8B1C004F6C1F /* WebService */,
|
||||||
ECE5812C181A77090066D073 /* ipbcAppDelegate.h */,
|
ECE5812C181A77090066D073 /* ipbcAppDelegate.h */,
|
||||||
ECE5812D181A77090066D073 /* ipbcAppDelegate.m */,
|
ECE5812D181A77090066D073 /* ipbcAppDelegate.m */,
|
||||||
ECE5812F181A77090066D073 /* MainMenu.xib */,
|
ECE5812F181A77090066D073 /* MainMenu.xib */,
|
||||||
@ -154,6 +161,17 @@
|
|||||||
name = "Supporting Files";
|
name = "Supporting Files";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
ECE6FED7181E8B1C004F6C1F /* WebService */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
ECE6FED4181E8AFD004F6C1F /* WebserviceClient.h */,
|
||||||
|
ECE6FED5181E8AFD004F6C1F /* WebserviceClient.m */,
|
||||||
|
ECE6FED8181E8BE4004F6C1F /* WebServiceConstants.h */,
|
||||||
|
ECE6FED9181E8BE4004F6C1F /* WebServiceConstants.m */,
|
||||||
|
);
|
||||||
|
name = WebService;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
/* Begin PBXNativeTarget section */
|
||||||
@ -256,8 +274,10 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
ECE6FEDA181E8BE4004F6C1F /* WebServiceConstants.m in Sources */,
|
||||||
ECE5812E181A77090066D073 /* ipbcAppDelegate.m in Sources */,
|
ECE5812E181A77090066D073 /* ipbcAppDelegate.m in Sources */,
|
||||||
ECE58127181A77090066D073 /* main.m in Sources */,
|
ECE58127181A77090066D073 /* main.m in Sources */,
|
||||||
|
ECE6FED6181E8AFE004F6C1F /* WebserviceClient.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -470,6 +490,7 @@
|
|||||||
ECE5814A181A77090066D073 /* Release */,
|
ECE5814A181A77090066D073 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
ECE5814B181A77090066D073 /* Build configuration list for PBXNativeTarget "ipbc-ClientTests" */ = {
|
ECE5814B181A77090066D073 /* Build configuration list for PBXNativeTarget "ipbc-ClientTests" */ = {
|
||||||
isa = XCConfigurationList;
|
isa = XCConfigurationList;
|
||||||
@ -478,6 +499,7 @@
|
|||||||
ECE5814D181A77090066D073 /* Release */,
|
ECE5814D181A77090066D073 /* Release */,
|
||||||
);
|
);
|
||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
@ -721,7 +721,7 @@
|
|||||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hXp-Wv-qfT">
|
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hXp-Wv-qfT">
|
||||||
<rect key="frame" x="131" y="49" width="332" height="147"/>
|
<rect key="frame" x="131" y="49" width="332" height="147"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="You need an ip-breadcrump.orc account to use this software." id="PYW-tK-cnY">
|
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="You need an ip-breadcrump.org account to use this software." id="PYW-tK-cnY">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -755,5 +755,6 @@ Gw
|
|||||||
</subviews>
|
</subviews>
|
||||||
</view>
|
</view>
|
||||||
</window>
|
</window>
|
||||||
|
<customObject id="QYg-I7-rYj" customClass="WebserviceClient"/>
|
||||||
</objects>
|
</objects>
|
||||||
</document>
|
</document>
|
||||||
16
ipbc-Client/ipbc-Client/WebServiceConstants.h
Normal file
16
ipbc-Client/ipbc-Client/WebServiceConstants.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// WebServiceConstants.h
|
||||||
|
// ipbc-Client
|
||||||
|
//
|
||||||
|
// Created by Gerrit Linnemann on 28.10.13.
|
||||||
|
// Copyright (c) 2013 Adawim UG (haftungsbeschränkt). All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@interface WebServiceConstants : NSObject
|
||||||
|
|
||||||
|
extern NSString * const WS_RESOURCE;
|
||||||
|
extern NSString * const WS_GET_USERS_IP_SERVICE;
|
||||||
|
|
||||||
|
@end
|
||||||
16
ipbc-Client/ipbc-Client/WebServiceConstants.m
Normal file
16
ipbc-Client/ipbc-Client/WebServiceConstants.m
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// WebServiceConstants.m
|
||||||
|
// ipbc-Client
|
||||||
|
//
|
||||||
|
// Created by Gerrit Linnemann on 28.10.13.
|
||||||
|
// Copyright (c) 2013 Adawim UG (haftungsbeschränkt). All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "WebServiceConstants.h"
|
||||||
|
|
||||||
|
@implementation WebServiceConstants
|
||||||
|
|
||||||
|
NSString * const WS_RESOURCE = @"http://www.ip-bc.org/ws/update/ip";
|
||||||
|
NSString * const WS_GET_USERS_IP_SERVICE = @"http://www.ip-bc.org/ws/info/ip";
|
||||||
|
|
||||||
|
@end
|
||||||
19
ipbc-Client/ipbc-Client/WebserviceClient.h
Normal file
19
ipbc-Client/ipbc-Client/WebserviceClient.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// WebserviceClient.h
|
||||||
|
// ipbc-Client
|
||||||
|
//
|
||||||
|
// Created by Gerrit Linnemann on 28.10.13.
|
||||||
|
// Copyright (c) 2013 Adawim UG (haftungsbeschränkt). All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@interface WebserviceClient : NSObject {
|
||||||
|
|
||||||
|
NSTimer *updateTimer;
|
||||||
|
NSString *usersIPv4;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(BOOL)updateDomain;
|
||||||
|
|
||||||
|
@end
|
||||||
114
ipbc-Client/ipbc-Client/WebserviceClient.m
Normal file
114
ipbc-Client/ipbc-Client/WebserviceClient.m
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
//
|
||||||
|
// WebserviceClient.m
|
||||||
|
// ipbc-Client
|
||||||
|
//
|
||||||
|
// Created by Gerrit Linnemann on 28.10.13.
|
||||||
|
// Copyright (c) 2013 Adawim UG (haftungsbeschränkt). All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "WebserviceClient.h"
|
||||||
|
#import "WebServiceConstants.h"
|
||||||
|
|
||||||
|
@implementation WebserviceClient
|
||||||
|
|
||||||
|
-(void)awakeFromNib {
|
||||||
|
updateTimer = [NSTimer scheduledTimerWithTimeInterval: 4
|
||||||
|
target: self
|
||||||
|
selector: @selector(tick:)
|
||||||
|
userInfo: nil
|
||||||
|
repeats: YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tick:(NSTimer *)theTimer {
|
||||||
|
[self updateDomain];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(BOOL)updateDomain {
|
||||||
|
usersIPv4 = [self fetchIPv4];
|
||||||
|
NSString *storedIPv4 = [[NSUserDefaults standardUserDefaults] stringForKey:@"value.ip.ipv4"];
|
||||||
|
if(storedIPv4 == nil) {
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:usersIPv4 forKey:@"value.ip.ipv4"];
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL updateResult = NO;
|
||||||
|
|
||||||
|
if([self checkUpdateNeeded]) {
|
||||||
|
NSLog(@"update resource: %@", WS_RESOURCE);
|
||||||
|
updateResult = [self doWebServiceUpdate];
|
||||||
|
} else {
|
||||||
|
NSLog(@"no update");
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(BOOL)checkUpdateNeeded {
|
||||||
|
NSString *storedIPv4 = [[NSUserDefaults standardUserDefaults] stringForKey:@"value.ip.ipv4"];
|
||||||
|
NSString *fetchedIPv4 = usersIPv4;
|
||||||
|
|
||||||
|
if(storedIPv4 == nil) {
|
||||||
|
NSLog(@"stored IPv4 NULL");
|
||||||
|
return YES;
|
||||||
|
} else if(fetchedIPv4 == nil) {
|
||||||
|
NSLog(@"fetched IPv4 NULL");
|
||||||
|
return NO;
|
||||||
|
} else {
|
||||||
|
//NSLog(@"compare stored %@ with %@", storedIPv4, fetchedIPv4);
|
||||||
|
BOOL changed = [storedIPv4 isEqualToString:fetchedIPv4];
|
||||||
|
|
||||||
|
if(changed) {
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:fetchedIPv4 forKey:@"value.ip.ipv4"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(BOOL)doWebServiceUpdate {
|
||||||
|
NSString *settingTempName = [[NSUserDefaults standardUserDefaults] stringForKey:@"setting.name"];
|
||||||
|
NSString *settingTempToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"setting.token"];
|
||||||
|
|
||||||
|
NSURL *url = [NSURL URLWithString:WS_RESOURCE];
|
||||||
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
|
||||||
|
[request setHTTPMethod:@"POST"];
|
||||||
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||||
|
|
||||||
|
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||||
|
settingTempName, @"domain",
|
||||||
|
settingTempToken, @"token",
|
||||||
|
nil];
|
||||||
|
NSError *error;
|
||||||
|
NSData *postData = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:&error];
|
||||||
|
[request setHTTPBody:postData];
|
||||||
|
|
||||||
|
NSLog(@"update ip to %@", usersIPv4);
|
||||||
|
//NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
|
||||||
|
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
|
||||||
|
|
||||||
|
NSString *strData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
|
||||||
|
NSLog(@"data: %@", strData);
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
/*NSString *post = [NSString stringWithFormat:@"name=%@&token=%@", settingTempName, settingTempToken];
|
||||||
|
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
|
||||||
|
|
||||||
|
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
|
||||||
|
|
||||||
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||||
|
[request setURL:[NSURL URLWithString:WS_RESOURCE]];
|
||||||
|
[request setHTTPMethod:@"POST"];
|
||||||
|
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
|
||||||
|
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
|
||||||
|
[request setHTTPBody:postData];*/
|
||||||
|
}
|
||||||
|
|
||||||
|
-(NSString *)fetchIPv4 {
|
||||||
|
NSURL *myIpAdress = [NSURL URLWithString:WS_GET_USERS_IP_SERVICE];
|
||||||
|
NSString *contentOfURL = [NSString stringWithContentsOfURL:myIpAdress encoding:NSUTF8StringEncoding error:NULL];
|
||||||
|
NSString *contentTrimmed = [contentOfURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||||
|
|
||||||
|
//NSLog(@"fetched IPv4: %@", contentTrimmed);
|
||||||
|
return contentTrimmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
Loading…
x
Reference in New Issue
Block a user