diff --git a/src/chat/cpim/parser/cpim-parser.cpp b/src/chat/cpim/parser/cpim-parser.cpp index 23fa0a360..96d63e499 100644 --- a/src/chat/cpim/parser/cpim-parser.cpp +++ b/src/chat/cpim/parser/cpim-parser.cpp @@ -29,10 +29,6 @@ #include "object/object-p.h" #include "cpim-parser.h" -#ifdef __APPLE__ -#include -#include -#endif #define CPIM_GRAMMAR "cpim_grammar" @@ -583,18 +579,7 @@ public: Cpim::Parser::Parser () : Singleton(*new ParserPrivate) { L_D(); - #if TARGET_OS_IPHONE - CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("org.linphone.linphone")); - CFURLRef grammarUrl = CFBundleCopyResourceURL(bundle, CFSTR(CPIM_GRAMMAR), nullptr, nullptr); - CFStringRef grammarPath = CFURLCopyFileSystemPath(grammarUrl, kCFURLPOSIXPathStyle); - CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); - const char *path = CFStringGetCStringPtr(grammarPath, encodingMethod); - CFRelease(grammarUrl); - CFRelease(grammarPath); - #else - const char *path = CPIM_GRAMMAR; - #endif - d->grammar = belr::GrammarLoader::get().load(path); + d->grammar = belr::GrammarLoader::get().load(CPIM_GRAMMAR); if (!d->grammar) lFatal() << "Unable to load CPIM grammar."; } diff --git a/src/core/platform-helpers/ios-platform-helpers.cpp b/src/core/platform-helpers/ios-platform-helpers.cpp index 6e9ed2f5b..8aa14cec4 100644 --- a/src/core/platform-helpers/ios-platform-helpers.cpp +++ b/src/core/platform-helpers/ios-platform-helpers.cpp @@ -20,9 +20,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef __APPLE__ #include "TargetConditionals.h" #endif - #if TARGET_OS_IPHONE +#include + +#include + #include "linphone/utils/general.h" #include "linphone/utils/utils.h" @@ -56,6 +59,7 @@ public: private: void bgTaskTimeout (); static void sBgTaskTimeout (void *data); + static const char *directoryForResource (CFStringRef framework, CFStringRef resource); long int mCpuLockTaskId; int mCpuLockCount; @@ -66,7 +70,20 @@ private: IosPlatformHelpers::IosPlatformHelpers (LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) { mCpuLockCount = 0; mCpuLockTaskId = 0; - lInfo() << "IosPlatformHelpers is fully initialised"; + + const char *cpimPath = directoryForResource(CFSTR("org.linphone.linphone"), CFSTR("cpim_grammar")); + const char *vcardPath = directoryForResource(CFSTR("org.linphone.belcard"), CFSTR("vcard_grammar")); + if (cpimPath) + belr::GrammarLoader::get().addPath(cpimPath); + else + lError() << "IosPlatformHelpers did not find cpim grammar resource directory..."; + + if (vcardPath) + belr::GrammarLoader::get().addPath(vcardPath); + else + lError() << "IosPlatformHelpers did not find vcard grammar resource directory..."; + + lInfo() << "IosPlatformHelpers is fully initialised."; } // ----------------------------------------------------------------------------- @@ -108,6 +125,19 @@ void IosPlatformHelpers::releaseCpuLock () { mCpuLockTaskId = 0; } +const char *IosPlatformHelpers::directoryForResource (CFStringRef framework, CFStringRef resource) { + CFBundleRef bundle = CFBundleGetBundleWithIdentifier(framework); + CFURLRef grammarUrl = CFBundleCopyResourceURL(bundle, resource, nullptr, nullptr); + CFURLRef grammarUrlDirectory = CFURLCreateCopyDeletingLastPathComponent(nullptr, grammarUrl); + CFStringRef grammarPath = CFURLCopyFileSystemPath(grammarUrlDirectory, kCFURLPOSIXPathStyle); + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + const char *path = CFStringGetCStringPtr(grammarPath, encodingMethod); + CFRelease(grammarUrl); + CFRelease(grammarPath); + CFRelease(grammarUrlDirectory); + return path; +} + // ----------------------------------------------------------------------------- PlatformHelpers *createIosPlatformHelpers (LinphoneCore *lc, void *system_context) {