libphonenumber for iOS or objective-c port - iphone

My goal is to use libphonenumber, google's phone number handling library for an iPhone project I'm working on.
After downloading it (and many many hours), I complied the C++ version of the library, and it built a number ".a" files and ".dylib" files, of which I assumed I must import into my xCodeProject in order to access those C++ functions.
So I imported "libphonenumber.a" into my project, updated my target, build settings, build phases, and Library Search Paths as needed.
Building the xCode project for Device & Simulator pass, however give me the following warning:
"ld: warning: ignoring file ../XcodeProjects/libphonenumber/build/libphonenumber.dylib, file was built for unsupported file format which is not the architecture being linked (armv7)". (or i386 when compiling for simulator)
I understand from this that I must compile the libphonenumber for the correct i386 and/or armv7 architecture. So I tried to do that, but quickly realized this requires me to also rebuild libphonenumber's 3 dependent libraries as well, for the i386/armv7 architectures in order for libphonenumber's to now properly compile. Eventually, I gave up on that, it started to look like a big mess ahead of me.
After all my trials, I'm left with
3 Questions:
1) How to I compile libphonenumber C++ library for use with i386/armv6/armv7 architectures.
2) When using a c++ library, is my assumption correct? Is it a matter of simply importing the ".a" file that results from the compilation, and just point to it in the header of my xCode project files? What exactly are the steps for including and using c++ libraries and accessing their functions from objective-c inside xCode?
3) I did find LPNKit, an objective-c port for libphonenumber, however it is incomplete. Has anyone heard of it, and had any luck using it? Or does anyone have an objective-c port for libphonenumber that is complete, working, with instructions on how to compile and install it correctly?
Any help or advice on how to get this library working on iOS would be greatly appreciated.
Update:
I ended up using the javascript version of libphonenumber, adding all the files to my bundle, including all referenced javascript libraries and using UIWebview and stringByEvaluatingJavaScriptFromString to run functions. You could also have the UIWebview reference the javascript library online (I just preferred to have everything local as not to depend on an internet connection).
Here is a sample of what I did:
webView_ = [[UIWebView alloc] init];
[webView_ loadHTMLString:
#"<script src='base.js'></script>"
"<script>"
"goog.require('goog.dom');"
"goog.require('goog.json');"
"goog.require('goog.proto2.ObjectSerializer');"
"goog.require('goog.string.StringBuffer');"
"</script>"
"<script src=\"phonemetadata.pb.js\"></script>"
"<script src=\"phonenumber.pb.js\"></script>"
"<script src=\"metadata.js\"></script>"
"<script src=\"phonenumberutil.js\"></script>"
"<script src=\"asyoutypeformatter.js\"></script>"
"<script src=\"normalize.js\"></script>"
baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
NSString *function = [[NSString alloc] initWithFormat: #"phoneNumberParser('%#','%#','')", phoneNumber, ISOCountryCode];
NSLog(#"function is: %#", function);
NSString *result =[webView_ stringByEvaluatingJavaScriptFromString:function];
The result variable gets me the formatted number.
I hope that helps anyone who ran into the same issue I did.

It has been ported by our team.
You can find it https://github.com/me2day/libPhoneNumber-iOS

Just note that libphonenumber Javascript library includes Google's closure library.
So you should consider, wrapping your Javascript call in a Javascript object and then compile it using closure builder in order to get an efficient and light weight script. (closure library before compilation : 18Mb, after compilation 300Kb !)
See above a sample of such a wrapper
goog.provide('sphone.phonenumber');
goog.require('goog.dom');
goog.require('goog.json');
goog.require('goog.proto2.ObjectSerializer');
goog.require('goog.array');
goog.require('goog.proto2.PbLiteSerializer');
goog.require('goog.string');
goog.require('goog.proto2.Message');
goog.require('goog.string.StringBuffer');
goog.require('i18n.phonenumbers.NumberFormat');
goog.require('i18n.phonenumbers.PhoneNumber');
goog.require('i18n.phonenumbers.PhoneNumberUtil');
sphone.phonenumber = function(phoneNumber, regionCode) {
this.getCountryCallCode=phonenumberGetCountryCallCode;
};
function phonenumberGetCountryCallCode(phoneNumber, regionCode) {
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phoneNumber, regionCode);
return number.getCountryCode();
};
// Ensures the symbol will be visible after compiler renaming.
goog.exportSymbol('sphone.phonenumber', sphone.phonenumber);

1) Fix all the errors and re-compile all the dependencies for arm. As you said before.
2) Yes. According to kstenerud’s iOS-Universal-Framework
Using an iOS Framework
iOS frameworks are basically the same as regular dynamic Mac OS X frameworks, except they are statically linked.
To add a framework to your project, simply drag it into your project. When including headers from your framework, remember to use angle bracket syntax rather than quotes.
For example, with framework "MyFramework":
#import <MyFramework/MyClass.h>
This question Importing an external library in xcode - C++ follows like this: Import C++ library, use it, get errors from its dependency on built-in frameworks, import those built-in frameworks, everything works.
3) I would invest in LPNKit instead of fighting your way through option 1. You can both contribute and benefit from LPNKit. GitHub is a wonderful place and the great boost of this over option 1 is that you have another person (or people!) who have the same goal and will all work together to achieve it.

Related

Compiler error when using AlwaysRightInstitute/SwiftSockets

I'm try to write a small game on IOS using socket and I've had a java socket server running with Flash client, but I got complier errors when I add the AlwaysRightInstitute/SwiftSockets source code to my swift project, and I did nothing after doing this
Here is the project structure:
the selected group "ARISockets" is the source code I drag into my project
and here are the errors(Use of unresolved identifier 'ari_fcntIVi'):
It seems that the errors cause by lack of some import file and I found "ari_fcntIVi" in ARISockets/UnixBridge.c,but I'm a really newer to Swift/Objective-C/C (I'm a AS3 developer), so that sucks me :/
I had the same problem with this library.
You need to create a Bridge file similar to "Import Objective-C into Swift" but this is C:
How to call Objective-C code from Swift
The issue was that you just copied over the sources instead of embedding the SwiftSockets framework. The ari_ prefixed functions used to required the bridging header of the SwiftSockets framework.
Having said that, the current SwiftSockets doesn't use bridging headers anymore, and you can directly embed the sources.

how to run games or apps within one project --iPhone/iPad/iOS

I want to add a game into my current project, the game and my current project are two separate projects, so how could I combine them to one?
I have thought of two possible solutions:
Merge the source code. But I don't want to do this, as it's so much trouble and very cumbersome.
Packaging the game into .app or .ipa or .a or something else, then import this game package to project, but I don't know how to run it with Objective-C code.
In fact, the second method is described below.
NSWorkspace *workspacce = [NSWorkspace sharedWorkspace]; 
NSString * appPath = [[workspacce activeApplication] objectForKey:#"NSApplicationPath"];
appPath = [appPath stringByDeletingLastPathComponent]; 
appPath = [appPath stringByAppendingPathComponent:#"/CSVEdit.app"];
[workspacce launchApplication:appPath];
[[NSWorkspace sharedWorkspace] launchApplication:#"a`enter code here`ppName"] ;
Does anyone have a more effective or simple solution?
I think merging is the only option. Because it's not allowed to launch another App.
Apps that install or launch other executable code will be rejected
Chapter 2 Functionality point 2.8 written in the terms.

Including a static library inside a dynamic framework in iOS

I needed to create a framework (which requires a static library) for a project I'm working on. I used this tutorial to create the framework, then copied the static library into the project and it worked.
But, when I dragged the framework to an iOS project, it shows a ton of errors.
`Undefined symbols for architecture i386:"_OBJC_CLASS_$_SomeClassFromTheStaticLibrary",referenced from:_OBJC_CLASS_$_AnotherClass in MyFramework`
What I think is happening is that the iOS project wants to recompile the framework and it cannot, because it can't locate the static library. All errors disappear if I add the static library to the iOS project. This is what I want to avoid.
Basically I want to have the iOS project -> Framework -> Library instead of having the library in both the project and the framework.
I have tried adding the static library as a resource in the framework, but it didn't work.
I doubt this is possible. When you think about what is happening you will see the problem.
The framework is compiled and the static library is processed so that things like extra symbols are stripped out
The app is now compiled and linked against the framework which may or may not have had the symbols that the app is requiring
I did get this to work if ONLY the framework was using the static library (logical) but I can't find a way to share the code across the framework & the app.
If a symbol is hidden (either via Symbols Hidden by Default/GCC_SYMBOLS_PRIVATE_EXTERN being set to YES or __attribute__ ((visibility ("hidden"))) being applied to certain symbols), then that symbol will be available when statically linking the library, but not when dynamically linking the framework.
Ensure that the static library's symbols are not hidden, and you should be able to access them from your app.
I have followed this link to create custom framework. I have static library inside my framework and it works fine with that.
I have copied his steps in my blog for my understanding along with a script to make it universal.

Is there a native YAML library for iPhone?

I'm considering using YAML as part of my next iPhone application, but I haven't been able to find an Objective-C library to use.
The Wikipedia page for YAML mentions one, but the link is dead.
Is there an Objective-C library that can parse YAML into native collection objects (NSArray, NSDictionary, etc...)?
The Cocoa extensions for Syck are probably what you're looking for -- it's where the library that Shaggy Frog mentioned seems to be living these days.
You can try YAML.framework it's LibYAML based, it's fast and easy to use. Follows the same pattern as standard NSPropertyListSerialization.
You can use it for iOS (iPhone/iPad) development.
The YAMLKit framework is a thin wrapper around LibYAML. It does exactly what you want. For example:
[[YKParser alloc] init];
[p readString:#"- foo\n- bar\n- baz"];
id result = [p parse];
/* result is now an NSArray containing an NSArray with elements:
#"foo", #"bar", #"baz" */
[p release];
I recently wrote modern ObjC-YAML bindings, based on the standard NSCoder/NSKeyedArchiver interface: http://github.com/th-in-gs/YACYAML. I'm using them in my own projects, and intend to maintain them for at least as long as I continue to do so.
More here: http://www.blog.montgomerie.net/yacyaml
IF you are doing alot of c++ in your iPhone projects, then please have a look at yaml-cpp:
http://code.google.com/p/yaml-cpp/
has native iPhone support (via it's cmake build system)
has no dependencies beyond a good compiler and cmake
is very c++ friendly (thus, the name) with solid documentation (see the wiki/HowToParseADocument page)
I found this right from YAML's front page. But it looks like it might be out of date (c. 2004?), and the CVS link doesn't work for me.
I would bet that it's just a thin wrapper around an underlying C library like this or this... C code being "native" code that the Objective-C compiler will grok.
I found this question looking for YAML + objective C options. I ended up using this solution: https://github.com/icanzilb/JSONModel. Very cool, up to date and easy to use. Parses yaml directly into objective C models that you create inheriting the JSONModel class.

NSConcreteData vs NSData

I have added an extension to NSData (base64 extension), which I kept over a separate infrastructure class lib project. But when i use this method from my main project i am getting an error like this: "-[NSConcreteData encodeBase64]: unrecognized selector sent to instance 0x121e60'".
But if i keep the same class in my main project itself, this will execute with out any issue.
I call this method in the following way:
[dev setToken:[token encodeBase64]];
Please suggest why this is not working if i put the extension in another project. (I am already using some other extensions, eg. for NSDate, like this with out any issue.)
Is this on iPhone OS 3.0? The 3.0 SDK broke the use of -ObjC, but you usually are able to link in categories for a static library by adding the -all_load option to Other Linker Flags within your target application.
The issue is that the metadata necessary to configure a category is usually stripped by the linker because it appears to be dead. If you add the "-ObjC" LDFLAG to your project it will tell the linker to link all the potential ObjC info even if it appears to be dead.