Is it even possible for one iOS app to access another app's Caches directory? - iphone

I'm writing a unit test with GHUnit. I would like to check if a file is being generated in the Caches directory within the Library directory of another app. Is this feasible, or are apps prevented from accessing each others' Library directories? And if so, are there any possible workarounds for creating a unit test for this? Could I possibly store the generated file in a different directory, such as Documents, or would that not help?

On device it is not possible at all. In simulator you can theoretically do it if you know the random UUID that names the directory that the application is installed in.
But I would highly discourage you from even trying. Instead make the code you intend to test stand enough of it's own to be testable. A unit test that verifies if another application behaves is on it's own almost as useless as a unit test that verifies that you call an API with the correct arguments.

I don't understand the context that you're attempting to unit test, so maybe my answer is wrong, but what I get is that you want to access your other app because GHUnit builds as a separate app.
There should be no reason to do this - instead of beating the sandbox problem, let's go around the whole issue.
Why not run whatever cache-creating code you are trying to test in the first place from the test target app, and then check the Libary/Cache directory of your bundle?
That's all there should be to it.

Apps can only access their own folders within their sandbox. Is your unit testing app separate from your app that you want to verify the cache contents of?

No, what you would need to do is use url prefixes and have the methods to do whatever you need done registered by that application on install.

Related

iOS Application framework

I have created an ios application that can talk to the database and get the messages from the server and all i want to do now is to distribute this aplication as a templet and other application can import my current project and use it, Now i been went throw many tricks and tips such as making an Static framwork using xcode bundles and Aggregate target type and got it work with some script found hear: http://codefriend.blogspot.com.au/2011/09/creating-ios-framework-with-xcode4.html
what i want to know is whether its the correct approach for such a problem or should i been looking at something else. All i want to create is an framework for my team so that they can produce other application
without worrying about or writing same files and code again and again. And is it possible to bundle all the .xib and .html files too?
This is what we use to create framework:
https://github.com/kstenerud/iOS-Universal-Framework

Create an App within an App

I am being presented with a very interesting project. The task that I must complete is to figure out a way to allow a partner to be involved in an app without giving up their source code. The code will be included in the main bundle of the app so it is not dynamically stored. The partner has a fully functional app that is needed to be ran in a window within the main app at the appropriate time. I know having the partners create a web app would be ideal so it is treated like a webpage but I am more concerned with codes that must be written natively in iOS.
My question is what is the best way to go about solving this? In theory it is like an App within an App. Is there a way if they gave up their .app file I can include this in the bundle and then run it when I catch a certain event? Should I have the partners create their code in a framework and then import into the shell project? What is the best way to approach this problem?
If your 2nd-party doesn't want to provide you with the source code, why doesn't he compile it to object code then let you simply link it to your app?
By the way, at least on official (non-jailbroken) iDevices, apps can't 'embed' or 'open' one another in such a way - you can open an app programmatically if 1. it's a separate app 2. it has a registered special URL associated to its bundle.
Is there a way if they gave up their .app file I can include this in
the bundle and then run it when I catch a certain event?
No, you'll want to have them create a library instead. You can then include that library in your project.
Creating a library is as simple as:
Choose File->New...->Project... in Xcode.
Select the "Cocoa Touch Static Library" project template.
Add your code.
Build.
The result is a static library that you can add to your application(s). The library will contain the compiled code that you added, but doesn't include the source code. The library developer should provide whatever header files are necessary to use the code in the library.
An App within an App is possible however it requires a common data framework that allows one app to reference the same data without confusing the the source of and destination of the data.
Such a framework allows one app to interact with another app referencing the same data.

one code base for iphone generic application?

I have built a generic application which can handle different content data - but for each content data, it will be a different iphone application (with a different name).
I would like of couse to only keep one code base for all these different apps (as it would be easier maintenance) but I have 2 questions:
1- I would need to change the appname in the buildsettings, etc.. and may be it is going to be an overkill...? especially with the upload process then...? What are your experiences in that domain and what would you recommend me to do?
2- how can I have all the pictures for logo (Icon.png, etc...) to co-exist into one app? For the moment, I have a global variable (as a singleton pattern) that I switch to change appname and loaded data inside the program
Thanks in advance for your help
Cheers,
geebee
You can do this pretty easily, it's what most developers do in their lite versions. All you have to do is add another target to create a new app out of the same code and use that global variable.
In order to change the images included in the app you simply edit the target and under the copy bundle resources menu remove the unnecessary resources. You'll notice that when you add a new resource you have the option to include it in any one or more of your targets. Simply select the one that you want and it will only be accessible to that target.
The reason that this works is that each target can have its very own info.plist. All the settings and resources can be separate, and the code can be different using your #ifdef global_var.
Here's a slightly outdated tutorial that should get you started if you need it.
http://www.bit-101.com/blog/?p=2098
For each application name add one target.
Create one xyz-info.plist for each of the target. (in this case for the xyz.app)
In each of the xyz-info.plist assign the appropriate icon files etc.
Within your build phases for each of the targets you will define which images go with which app.

Equivalent to R in iOS

In android we have the R class that stands for Resources, where we have references to all of our resources and we can easily access them in the code. Is there an equivalent in iOS? I have this doubt because, I want to be able to define multiple files with different values, for instance:
DefaultValuesForViewController1
DefaultValuesForViewController2
Besides creating plist, is there another way (faster and easier like R)?
There is no R class equivalent access method.
In Android, the R class represents access to resources that are consolidated into a native format. iPhone does not do this. Instead, resource files are just copied as is into the application bundle and must be found & opened as such.
You could create a class to store all of your data for the app. iOS generally likes the app to run lean and mean, so only storing your objects for as long as you need them, releasing them as soon as you are done with them. If you were to store everything globally, it would add some overhead, but assuming you don't have a ton of information, it shouldn't be an issue.
There is no equivalent for this in iOS apps. All you get is files that you can enumerate using standard file I/O.
However, you can emulate it partially. Here's a simple demo on GitHub
You can find that SwiftGen(e.g. Tuist used it) can be used as an alternative for autogenerated R.java file on Android
Two point
it is third party source
you have to manually run script after changing your resources

How to share keychain data between iOS applications

I am describing a problem for which it took me quite some time to learn the answer.
The "GenericKeychain" example is a good start at providing a wrapper for sharing keychain data between applications when using the accessGroup in the init.
However, implementing this in my app yielded an obscure error code (which took forever to locate) -25243, which means: No access control.
I ran Apple's example app (GenericKeychain) on my iPad only to get the same error. Huh?
Does Apple's documentation fail to deliver on what is necessary to accomplish this?
After some (a lot of) digging throughout the web, I found the answer. The access Group that you use when constructing your KeychainItemWrapper class must ALSO be specified in each of your application's Entitlements.plist file in the "keychain-access-groups" section.
It seems almost obvious now that I see "keychain-access-groups". However, I had no idea to even look there. Hope this helps others.
Actually it's not hard to do. Please follow the steps.
App1:
Open your App's target Capabilities and enable KeyChain Sharing.
Add a identifier. (eg : com.example.sharedaccess)
Add "UICKeyChainStore" to your project.
Be sure you have a team id added to your App1 project.
Add Security.framework to your App1 project.
And add these codes to somewhere you need.
[UICKeyChainStore setString:#"someValue" forKey:#"someKey" service:#"someService"];
App2:
Open your App's target Capabilities and enable KeyChain Sharing.
Add a identifier. (eg : com.example.sharedaccess)
Add "UICKeyChainStore" to your project.
Be sure you have a team id added to your App2 project.
Add Security.framework to your App2 project.
And add these codes to somewhere you need.
NSString *string = [UICKeyChainStore stringForKey:#"someKey" service:#"someService"];
Your TeamIDs should be same for both projects.
I tried these steps on a real iPhone device.
I also tried these steps with Automatic and iOs Development provisioning profile.
My apps' bundle identifiers were like that : com.example.app1, com.example.app2.