Skip to content

Commit 37f3d36

Browse files
authored
Merge pull request iziz#304 from rastaarh/UpdatedGeocodingParser
Updated geocoding parser
2 parents d27172e + be50f56 commit 37f3d36

File tree

6 files changed

+198
-48
lines changed

6 files changed

+198
-48
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
target 'libPhoneNumber-GeocodingParser' do
2+
# Comment the next line if you don't want to use dynamic frameworks
3+
use_frameworks!
4+
5+
# Pods for libPhoneNumber-GeocodingParser
6+
pod 'SSZipArchive'
7+
end

libPhoneNumber-GeocodingParser/libPhoneNumber-GeocodingParser.xcodeproj/project.pbxproj

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
9439832424CA460700CF8CB4 /* SSZipArchive.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9439832324CA460700CF8CB4 /* SSZipArchive.framework */; };
11+
9439832524CA460700CF8CB4 /* SSZipArchive.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9439832324CA460700CF8CB4 /* SSZipArchive.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1012
9478476B24BCD14D004F5637 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478476A24BCD14D004F5637 /* main.m */; };
1113
9478477324BCD180004F5637 /* NBGeocoderMetadataParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478477224BCD180004F5637 /* NBGeocoderMetadataParser.m */; };
1214
9478477624BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 9478477524BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m */; };
15+
9BBB13F5268ECEF110BFB4A3 /* Pods_libPhoneNumber_GeocodingParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */; };
1316
/* End PBXBuildFile section */
1417

1518
/* Begin PBXCopyFilesBuildPhase section */
19+
9439832624CA460700CF8CB4 /* Embed Frameworks */ = {
20+
isa = PBXCopyFilesBuildPhase;
21+
buildActionMask = 2147483647;
22+
dstPath = "";
23+
dstSubfolderSpec = 10;
24+
files = (
25+
9439832524CA460700CF8CB4 /* SSZipArchive.framework in Embed Frameworks */,
26+
);
27+
name = "Embed Frameworks";
28+
runOnlyForDeploymentPostprocessing = 0;
29+
};
1630
9478476524BCD14D004F5637 /* CopyFiles */ = {
1731
isa = PBXCopyFilesBuildPhase;
1832
buildActionMask = 2147483647;
@@ -25,30 +39,56 @@
2539
/* End PBXCopyFilesBuildPhase section */
2640

2741
/* Begin PBXFileReference section */
42+
1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libPhoneNumber-GeocodingParser.debug.xcconfig"; path = "Target Support Files/Pods-libPhoneNumber-GeocodingParser/Pods-libPhoneNumber-GeocodingParser.debug.xcconfig"; sourceTree = "<group>"; };
43+
8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libPhoneNumber-GeocodingParser.release.xcconfig"; path = "Target Support Files/Pods-libPhoneNumber-GeocodingParser/Pods-libPhoneNumber-GeocodingParser.release.xcconfig"; sourceTree = "<group>"; };
44+
9439832324CA460700CF8CB4 /* SSZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SSZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2845
9478476724BCD14D004F5637 /* libPhoneNumber-GeocodingParser */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "libPhoneNumber-GeocodingParser"; sourceTree = BUILT_PRODUCTS_DIR; };
2946
9478476A24BCD14D004F5637 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3047
9478477124BCD180004F5637 /* NBGeocoderMetadataParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NBGeocoderMetadataParser.h; sourceTree = "<group>"; };
3148
9478477224BCD180004F5637 /* NBGeocoderMetadataParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NBGeocoderMetadataParser.m; sourceTree = "<group>"; };
3249
9478477424BCD1AB004F5637 /* NBSQLiteDatabaseConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NBSQLiteDatabaseConnection.h; sourceTree = "<group>"; };
3350
9478477524BCD1AB004F5637 /* NBSQLiteDatabaseConnection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NBSQLiteDatabaseConnection.m; sourceTree = "<group>"; };
51+
AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_libPhoneNumber_GeocodingParser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3452
/* End PBXFileReference section */
3553

3654
/* Begin PBXFrameworksBuildPhase section */
3755
9478476424BCD14D004F5637 /* Frameworks */ = {
3856
isa = PBXFrameworksBuildPhase;
3957
buildActionMask = 2147483647;
4058
files = (
59+
9BBB13F5268ECEF110BFB4A3 /* Pods_libPhoneNumber_GeocodingParser.framework in Frameworks */,
60+
9439832424CA460700CF8CB4 /* SSZipArchive.framework in Frameworks */,
4161
);
4262
runOnlyForDeploymentPostprocessing = 0;
4363
};
4464
/* End PBXFrameworksBuildPhase section */
4565

4666
/* Begin PBXGroup section */
67+
019E1F2D6D2F2646AA0F7A07 /* Frameworks */ = {
68+
isa = PBXGroup;
69+
children = (
70+
9439832324CA460700CF8CB4 /* SSZipArchive.framework */,
71+
AB42456B7D37F6CA481559F0 /* Pods_libPhoneNumber_GeocodingParser.framework */,
72+
);
73+
name = Frameworks;
74+
sourceTree = "<group>";
75+
};
76+
81942256806B519825D98257 /* Pods */ = {
77+
isa = PBXGroup;
78+
children = (
79+
1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */,
80+
8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */,
81+
);
82+
path = Pods;
83+
sourceTree = "<group>";
84+
};
4785
9478475E24BCD14D004F5637 = {
4886
isa = PBXGroup;
4987
children = (
5088
9478476924BCD14D004F5637 /* libPhoneNumber-GeocodingParser */,
5189
9478476824BCD14D004F5637 /* Products */,
90+
81942256806B519825D98257 /* Pods */,
91+
019E1F2D6D2F2646AA0F7A07 /* Frameworks */,
5292
);
5393
sourceTree = "<group>";
5494
};
@@ -79,9 +119,12 @@
79119
isa = PBXNativeTarget;
80120
buildConfigurationList = 9478476E24BCD14D004F5637 /* Build configuration list for PBXNativeTarget "libPhoneNumber-GeocodingParser" */;
81121
buildPhases = (
122+
78E19583AC36ED362B40DB2E /* [CP] Check Pods Manifest.lock */,
82123
9478476324BCD14D004F5637 /* Sources */,
83124
9478476424BCD14D004F5637 /* Frameworks */,
84125
9478476524BCD14D004F5637 /* CopyFiles */,
126+
9439832224CA428D00CF8CB4 /* ShellScript */,
127+
9439832624CA460700CF8CB4 /* Embed Frameworks */,
85128
);
86129
buildRules = (
87130
);
@@ -124,6 +167,48 @@
124167
};
125168
/* End PBXProject section */
126169

170+
/* Begin PBXShellScriptBuildPhase section */
171+
78E19583AC36ED362B40DB2E /* [CP] Check Pods Manifest.lock */ = {
172+
isa = PBXShellScriptBuildPhase;
173+
buildActionMask = 2147483647;
174+
files = (
175+
);
176+
inputFileListPaths = (
177+
);
178+
inputPaths = (
179+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
180+
"${PODS_ROOT}/Manifest.lock",
181+
);
182+
name = "[CP] Check Pods Manifest.lock";
183+
outputFileListPaths = (
184+
);
185+
outputPaths = (
186+
"$(DERIVED_FILE_DIR)/Pods-libPhoneNumber-GeocodingParser-checkManifestLockResult.txt",
187+
);
188+
runOnlyForDeploymentPostprocessing = 0;
189+
shellPath = /bin/sh;
190+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
191+
showEnvVarsInLog = 0;
192+
};
193+
9439832224CA428D00CF8CB4 /* ShellScript */ = {
194+
isa = PBXShellScriptBuildPhase;
195+
buildActionMask = 2147483647;
196+
files = (
197+
);
198+
inputFileListPaths = (
199+
);
200+
inputPaths = (
201+
);
202+
outputFileListPaths = (
203+
);
204+
outputPaths = (
205+
);
206+
runOnlyForDeploymentPostprocessing = 0;
207+
shellPath = /bin/sh;
208+
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n";
209+
};
210+
/* End PBXShellScriptBuildPhase section */
211+
127212
/* Begin PBXSourcesBuildPhase section */
128213
9478476324BCD14D004F5637 /* Sources */ = {
129214
isa = PBXSourcesBuildPhase;
@@ -249,7 +334,9 @@
249334
};
250335
9478476F24BCD14D004F5637 /* Debug */ = {
251336
isa = XCBuildConfiguration;
337+
baseConfigurationReference = 1174FF265138ABDB2DE27F14 /* Pods-libPhoneNumber-GeocodingParser.debug.xcconfig */;
252338
buildSettings = {
339+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
253340
CODE_SIGN_STYLE = Automatic;
254341
DEVELOPMENT_TEAM = 973LHT5R86;
255342
ENABLE_HARDENED_RUNTIME = YES;
@@ -259,7 +346,9 @@
259346
};
260347
9478477024BCD14D004F5637 /* Release */ = {
261348
isa = XCBuildConfiguration;
349+
baseConfigurationReference = 8FD4ACC3A7C4DC8DBDA891B2 /* Pods-libPhoneNumber-GeocodingParser.release.xcconfig */;
262350
buildSettings = {
351+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
263352
CODE_SIGN_STYLE = Automatic;
264353
DEVELOPMENT_TEAM = 973LHT5R86;
265354
ENABLE_HARDENED_RUNTIME = YES;

libPhoneNumber-GeocodingParser/libPhoneNumber-GeocodingParser.xcodeproj/xcshareddata/xcschemes/libPhoneNumber-GeocodingParser.xcscheme

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@
5050
ReferencedContainer = "container:libPhoneNumber-GeocodingParser.xcodeproj">
5151
</BuildableReference>
5252
</BuildableProductRunnable>
53-
<CommandLineArguments>
54-
<CommandLineArgument
55-
argument = "/Users/rastaar/Documents/geocoding"
56-
isEnabled = "YES">
57-
</CommandLineArgument>
58-
<CommandLineArgument
59-
argument = "/Users/rastaar/Desktop"
60-
isEnabled = "YES">
61-
</CommandLineArgument>
62-
</CommandLineArguments>
6353
</LaunchAction>
6454
<ProfileAction
6555
buildConfiguration = "Release"

libPhoneNumber-GeocodingParser/libPhoneNumber-GeocodingParser.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

libPhoneNumber-GeocodingParser/libPhoneNumber-GeocodingParser/main.m

Lines changed: 84 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,106 @@
88

99
#import <Foundation/Foundation.h>
1010
#import "NBGeocoderMetadataParser.h"
11+
#import "SSZipArchive.h"
1112

1213
int main(int argc, const char *argv[]) {
1314
@autoreleasepool {
14-
if (argc != 3) {
15-
NSLog(@"The libPhoneNumber-iOS Geocoder Parser requires two input arguments to properly "
15+
if (argc != 2) {
16+
NSLog(@"The libPhoneNumber-iOS Geocoder Parser requires 1 input arguments to properly "
1617
@"function.");
17-
NSLog(@"1. The complete folder path where the libPhoneNumber geocoding resource folder "
18-
@"(found at: https://github.com/google/libphonenumber/tree/master/resources/geocoding) "
19-
@"is stored on disk.");
20-
NSLog(@"2. The complete directory path to the desired location to store the corresponding "
18+
NSLog(@"1. The complete directory path to the desired location to store the corresponding "
2119
@"SQLite databases created.");
22-
NSLog(@"Example arguments: Users/JohnDoe/Documents/geocoding Users/JohnDoe/Desktop");
20+
NSLog(@"Example argument: Users/JohnDoe/Desktop");
2321
} else {
24-
NSString *geocodingMetadataDirectory = @(argv[1]);
25-
NSURL *databaseDesiredLocation = [NSURL fileURLWithPath:@(argv[2])];
26-
NBGeocoderMetadataParser *metadataParser =
27-
[[NBGeocoderMetadataParser alloc] initWithDestinationPath:[databaseDesiredLocation copy]];
22+
// Download zip file from GitHub.
23+
NSString *repositoryString = @"https://github.com/google/libphonenumber/archive/master.zip";
24+
NSURL *databaseDesiredLocation = [NSURL fileURLWithPath:@(argv[1])];
25+
NSURL *libPhoneNumberRepoURL = [NSURL URLWithString:repositoryString];
26+
27+
NSLog(@"Downloading geocoding metadata files from %@", repositoryString);
28+
NSData *libPhoneNumberData = [NSData dataWithContentsOfURL:libPhoneNumberRepoURL];
29+
NSLog(@"Downloaded geocoding metadata files.");
30+
31+
// Gather the documents directory path
32+
NSString *temporaryDirectoryPath = NSTemporaryDirectory();
33+
NSString *zipFilePath =
34+
[temporaryDirectoryPath stringByAppendingPathComponent:@"/libPhoneNumber-iOS.zip"];
35+
zipFilePath = [zipFilePath stringByStandardizingPath];
36+
[libPhoneNumberData writeToFile:zipFilePath atomically:YES];
37+
NSLog(@"Attempting to unzip downloaded metadata.");
38+
39+
// Unzip libphonenumber-master project using SSZipArchive library.
40+
[SSZipArchive unzipFileAtPath:zipFilePath toDestination:temporaryDirectoryPath];
41+
NSLog(@"Successfully unzipped metadata files.");
42+
43+
// Navigate through project to geocoding metadata resource files.
44+
NSString *libPhoneNumberFolderPath =
45+
[NSString stringWithFormat:@"%@/libphonenumber-master", temporaryDirectoryPath];
2846
NSError *error;
29-
NSArray *languages =
30-
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:geocodingMetadataDirectory
47+
NSArray *filesInDirectory =
48+
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:libPhoneNumberFolderPath
3149
error:&error];
32-
if (error != NULL) {
33-
NSLog(@"Error occurred when trying to read directory: %@"
34-
@"Error message: %@",
35-
geocodingMetadataDirectory, [error localizedDescription]);
50+
if (error != nil) {
51+
NSLog(@"An error occurred when attempting to access files in repository. Error message: %@",
52+
error.description);
3653
return 1;
3754
}
38-
NSArray *textFilesAvailable;
39-
NSString *languageFolderPath;
40-
for (NSString *language in languages) {
41-
NSLog(@"Creating SQLite database file for the language: %@", language);
42-
languageFolderPath =
43-
[NSString stringWithFormat:@"%@/%@", geocodingMetadataDirectory, language];
44-
textFilesAvailable =
45-
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:languageFolderPath
55+
if ([filesInDirectory containsObject:@"resources"]) {
56+
NSString *resourcesFolderPath =
57+
[NSString stringWithFormat:@"%@/resources", libPhoneNumberFolderPath];
58+
filesInDirectory =
59+
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcesFolderPath
4660
error:&error];
4761
if (error != NULL) {
48-
NSLog(@"Error occurred when trying to read files for the language directory: %@",
49-
languageFolderPath);
50-
error = NULL;
51-
continue;
62+
NSLog(@"An error occurred when attempting to access files in project's 'resources' "
63+
@"folder. Error message: %@",
64+
error.description);
65+
return 1;
5266
}
53-
for (NSString *filename in textFilesAvailable) {
54-
NSString *extension = [[filename pathExtension] lowercaseString];
67+
if ([filesInDirectory containsObject:@"geocoding"]) {
68+
NSString *geocodingFolderPath =
69+
[NSString stringWithFormat:@"%@/geocoding", resourcesFolderPath];
70+
NSArray *languages =
71+
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:geocodingFolderPath
72+
error:&error];
73+
if (error != NULL) {
74+
NSLog(@"An error occurred when attempting to access files in project's 'geocoding' "
75+
@"folder. Error message: %@",
76+
error.description);
77+
return 1;
78+
}
79+
NBGeocoderMetadataParser *metadataParser = [[NBGeocoderMetadataParser alloc]
80+
initWithDestinationPath:[databaseDesiredLocation copy]];
81+
82+
NSArray *textFilesAvailable;
83+
NSString *languageFolderPath;
84+
for (NSString *language in languages) {
85+
NSLog(@"Creating SQLite database file for the language: %@", language);
86+
languageFolderPath =
87+
[NSString stringWithFormat:@"%@/%@", geocodingFolderPath, language];
88+
textFilesAvailable =
89+
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:languageFolderPath
90+
error:&error];
91+
if (error != NULL) {
92+
NSLog(@"Error occurred when trying to read files for the language directory: %@",
93+
languageFolderPath);
94+
error = NULL;
95+
continue;
96+
}
97+
for (NSString *filename in textFilesAvailable) {
98+
NSString *extension = [[filename pathExtension] lowercaseString];
5599

56-
if ([extension isEqualToString:@"txt"]) {
57-
NSString *completeFilePath =
58-
[NSString stringWithFormat:@"%@/%@", languageFolderPath, filename];
59-
[metadataParser convertFileToSQLiteDatabase:completeFilePath
60-
withFileName:filename
61-
withLanguage:language];
100+
if ([extension isEqualToString:@"txt"]) {
101+
NSString *completeFilePath =
102+
[NSString stringWithFormat:@"%@/%@", languageFolderPath, filename];
103+
[metadataParser convertFileToSQLiteDatabase:completeFilePath
104+
withFileName:filename
105+
withLanguage:language];
106+
}
107+
}
108+
NSLog(@"Created SQLite database file for the language: %@", language);
62109
}
63110
}
64-
NSLog(@"Created SQLite database file for the language: %@", language);
65111
}
66112
}
67113
}

0 commit comments

Comments
 (0)