NSBundle from my library is nil - bundle

I created my own iOS library with core data inside,
as suggested here.
I added library to my project and build is success, but when I am trying to load the database:
bundleWithIdentifier method for my bundle returns nil.
NSBundle * testBundle = [NSBundle bundleWithIdentifier:#"result.BIModel"];
// testBundle = nil;
My library's bundle identifier is set(see image below), I added the framework to "Link Binary With Libraries" and "Embed Frameworks".
What am I missing ?
EDIT :
I notice that when framework is created one file is missing.
I build test framework (that works and bundleWithIdentifier return bundle) and get (see last file),
but when I build my framework i get
. See that last file is missing.

Related

Binding Deezer iOS SDK (Objective-C) into a Xamarin (C#) app

I'm developing a cross-platform mobile application, using Xamarin (with Xamarin Studio version 6.0.2).
I'm focusing on the iOS Part first.
I want to implement the Deezer SDK in my app
As the SDK is delivered is Objective-C, I need to bind it to C#, and this is where I have troubles.
I use Xamarin’s tool Objective Sharpie 3.3.0p, based on this walkthrough in order to generate the files ApiDefinition.cs and Structs.cs https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/.
Here is the details of what I did:
1) I downloaded the iOS SDK on Deezer developers website
2) I created an iOS Binding Library project on Xamarin
3) I used the FAT library file "libDeezer.a" as a native reference.
4) I ran the following command line:
sharpie bind -output ./DeezerAPI -namespace DeezerAPI -sdk iphoneos9.3 ./deezer-ios-sdk-v0/DeezerSDK/include/*.h
Note that I didn’t only try with targeting *.h. In fact, in the walkthrough it is said that I should target the top-level header file.
So I read carefully through those header files, and I couldn’t find a unique top-level header file. Actually, it came out to me that there are 6 top-level header files, as they are not called by any other header file.
Deezer+Compatibility.h
DZRGenericCancelable.h
DZRPlayableArray.h
DZRPlayer.h
DZRRequestManager.h
NSBundle+DZRBundle.h
I tried to target each of these files, separately and together.
The command worked well each time and delivered the ApiDefinition.cs and StructsAndEnums.cs files.
5) I copied and pasted the content of these files in the corresponding files of the Binding project, and merging the original "using" with the generated ones.
6) I tried to build the project and a bunch of errors came out.
Here are the errors that I have:
The type or namespace '$name' could not be found. Are you missing any
assembly reference ? with $name as (BaseType, Abstract, Wrap,
NullAllowed, StaticAttribute, HttpMethod, ResponseFormat,
BufferManager)
A member is already defined. Rename this member or use different parameters types. (I think sharpie just named two methods the same
way, and I just need to change the name of one of them)
Type byte, byte, short, ushort, int, uint, long, ulong expected. (ApiDefinition uses nuint and nint, I fixed it in changing them for
ulong and long)
Here is the Binding project with the files ApiDefinition.cs and Structs.cs that I have targeting the *.h:
https://github.com/aroy314/DeezerSDKBinding
I would be thankful if anyone could give me a hint about what is wrong and how to make with project work.

How to reference other frameworks from my binding?

I am trying to bind a library that depends on multiple frameworks. Here's the documentation on how to set it up on xcode: http://sdk.camera360.com/page/iosguide.
In essence it depends on the following external frameworks:
pg_edit_sdk_common.framework
pg_edit_sdk_cdb_piratesdk.framework
The following iOS Frameworks:
CoreMotion.framework
AVFoundation.framework
CoreMedia.framework
CoreData.framework
CoreGraphics.framework
CoreImage.framework
ImageIO.framework
libstdc++.6.dylib
libz.1.2.5.dylib
and it sounds like it also needs the flags:
-std=c++11 and -all_load
I am binding PhotoEditFrameWork.a utilizing Sharpie and a Binding Project. The PhotoEditFramework.linkwith.cs looks like this:
[assembly: LinkWith ("PhotoEditFramework.a", SmartLink = true, ForceLoad = true,
Frameworks="CoreMotion AVFoundation CoreMedia CoreData CoreGraphics CoreImage ImageIO",
LinkerFlags = "-all_load -lstdc++.6 -lz.1.2.5 -std=c++11")]
But when I try to run the app I get the following errors:
MTOUCH: error MT5209: Native linking error: warning: ignoring file /Code/Tests/Camera360/Camera360Test/obj/iPhoneSimulator/Debug/mtouch-cache/PhotoEditFramework.a, missing required architecture i386 in file /Code/Tests/Camera360/Camera360Test/obj/iPhoneSimulator/Debug/mtouch-cache/PhotoEditFramework.a (2 slices)
MTOUCH: error MT5214: Native linking failed, undefined symbol: _PhotoEditFrameworkVersionString. This symbol was referenced by the managed member Camera360.Constants.PhotoEditFrameworkVersionString. Please verify that all the necessary frameworks have been referenced and native libraries linked.
MTOUCH: error MT5214: Native linking failed, undefined symbol: _PhotoEditFrameworkVersionNumber. This symbol was referenced by the managed member Camera360.Constants.PhotoEditFrameworkVersionNumber. Please verify that all the necessary frameworks have been referenced and native libraries linked.
The first error is related to the simulator. Is that because the library is missing the i386 target?
I think the other two errors are related to references to pg_edit_sdk_common.framework and pg_edit_sdk_cdb_piratesdk.framework. How do I reference those two frameworks on LinkWith. Furthermore, do I need to bind those as well?
You're correct in your first assumption. The native library is likely missing a target for i386. You can confirm by following the directions here.
To fix the issue with the external frameworks, you can add as many required native libraries into the binding project as needed. In this case, grab the native .a file from both the required pg_*.framework files and add them into the binding project.
Note* After you add the .a libraries, you'll get more LinkWith.cs files for those libraries. Make sure the LinkTarget is set. I noticed your existing one does not have it either. Update that. It should be something like this:
LinkTarget = LinkTarget.ArmV6 | LinkTarget.ArmV7 | LinkTarget.Simulator
However, you'll need to make sure the LinkTargets match whatever the .a supports. Use the technique in the first link to check that (lipo -info)
There are also some other workarounds noted here if the above does not apply.

Undefined symbols for architecture x86_64 but error resources are inside built framework

I start develop iOS app using framework code I built myself from source code.
I added needed architectures to framework project and built framework, that add it to my application.
And when I tried to build application, Undefined symbols for architecture x86_64 errors was appeared, eg:
"_AES_ige_encrypt", referenced from:
_MTAesEncryptInplace in MTProtoKit iOS (MTEncryption.o)
_MTAesEncryptInplaceAndModifyIv in MTProtoKit iOS (MTEncryption.o)
...
"_AES_set_encrypt_key", referenced from:
_MTAesEncryptInplace in MTProtoKit iOS (MTEncryption.o)
_MTAesEncryptInplaceAndModifyIv in MTProtoKit iOS (MTEncryption.o)
...
And many others, not only at MTEncryption
I looked framework source, file MTEncryption.m:
void MTAesEncryptInplace(NSMutableData *data, NSData *key, NSData *iv)
{
AES_KEY aesKey;
AES_set_encrypt_key(key.bytes, 256, &aesKey); // <-- _AES_set_encrypt_key
unsigned char aesIv[AES_BLOCK_SIZE * 2];
memcpy(aesIv, iv.bytes, iv.length);
AES_ige_encrypt(data.bytes, (void *)data.bytes, data.length, &aesKey, aesIv, true); // <-- _AES_ige_encrypt
}
These methods are in .../openssl/aes.h that is already included to build phases.
But I noticed that aes.m file is missing (not just missing in build phases but file doesn't exist).Is it normal? Or exactly .m files missing is build failing reason? But if it's the reason, how framework was built successfully?
From scouting around the simulator files, i can't see a definitive iteration of aes or openssl which come "part and parcel".
On that note, you'd have to compile your own OpenSSL to support these missing libraries.
I did find a github repo for you that could be of help:
https://github.com/x2on/OpenSSL-for-iPhone
Hope this helps..

RestKit as part of static library / subproject

I am developing my own static library which is a sub-project of an iOS application (which I will call MyApp). This library (which I will call MySDK) provides a set of objects which are implementations of JSON structures returned from a RESTful web service. I am trying to use RestKit to handle the mapping between my web service and the objects in MySDK.
Prior to adding RestKit to MySDK, I had MySDK as a sub-project of MyApp, and everything compiled fine.
Then, I closed MyApp and opened the MySDK project. I added RestKit to MySDK project following the instructions here: https://github.com/RestKit/RestKit/wiki/Installing-RestKit-v0.20.x-as-a-Git-Submodule. Then, in one of MySDK's .h files, I added the line:
#import <RestKit/RestKit.h>
And I changed the line:
#interface MySDKObject : NSObject { /*...*/ }
to
#interface MySDKObject : NSObject<RKObjectLoaderDelegate> { /*...*/ }
Everything compiled fine. Then, I closed MySDK project and reopened MyApp project. The project navigator showed this relationship between the projects:
My App
MySDK
RestKit
In the code editor I now get this error:
#import <RestKit/RestKit.h> 'RestKit/RestKit.h' file not found
Oddly, in the Issue Navigator, this error message is reported under the My App target.

Xcode 4 : define a preprocessor macro in a dependent target

I have an app named MyApp which is linked to a static library MyLibrary
I've added the MyLibrary project to Xcode and added the MyLibrary target to MyApp's target dependencies.
All this works fine, I can set breakpoints, and I'm pretty happy.
The thing is that I want a conditional log in the library :
#ifdef DEBUG
# define MYDebug(msg, ...) NSLog(#"\nDEBUG -> %# \n(%s:%d)",[NSString stringWithFormat:msg, ## __VA_ARGS__], __PRETTY_FUNCTION__,__LINE__);
#else
# define MYDebug(msg, ...)
#endif
So I have two build configuration for my library :
- Debug has "DEBUG=1" in the target's build settings in "preprocessor macros"
- Prod has nothing
And the MyLibrary target is set to build with the Debug build configuration.
This works fine if I build the static library (.a), and include it in a project.
But if it is built by target dependency, it seems that DEBUG is not defined (MYDebug doesn't log anything).
I've also tried to set DEBUG=1 in MyApp's build settings, but it doesn't work.
Is there something I missed, or another way to do it ?
It should just be "DEBUG" instead of "DEBUG=1". Also, to use a macro that needs an Object assignment (NSString, etc) you need to escape most of the characters like # and " etc..
Here is a screenshot of a working project of mine from xCode 4.1:

Resources