Why can't app access another app's document folder? - iphone

We are trying to use inter-app communication for two application and trying to send the file path from one application to another application and the problem is that if i pass any text via sender application to receiver then it works well but if i try to pass the file document path then it doesn't works
here is my code for sender
-(IBAction) openReceiverApp:(id)sender {
// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory, #"ads.rtf"];
NSLog(#"filePath %#", filePath);
// NSString *URLEncodedText = [self.textBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *URLEncodedText = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *ourPath = [#"readtext://" stringByAppendingString:URLEncodedText];
NSLog(#"%#",ourPath);
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
else {
//Display error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Receiver Not Found" message:#"The Receiver App is not installed. It must be installed to send text." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
In receiver side i have written this code
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// Display text
UIAlertView *alertView;
NSString *text = [[url host]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
alertView = [[UIAlertView alloc] initWithTitle:#"Text" message:text delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return YES;
am i going wrong anywhere??
Thanks in advance....

The key word is Sandboxing. On iOS every app is sandboxed, which means it runs in it's own container and all data stored by the app should be secured against manipulation (read and write) of other apps.
It is impossible to access other apps Documents folder when the device is not jailbroken.

I am not sure if you managed to work it out. But i thought of sharing this info which might be useful.
Apple has released a new api in iOS8 to access documents outside your app’s sandbox.
Document Picker
The document picker view controller (UIDocumentPickerViewController) grants users access to files outside your application’s sandbox. It is a simple mechanism for sharing documents between apps. It also enables more complex workflows, because users can edit a single document with multiple apps.
The document picker lets you access files from a number of document providers. For example, the iCloud document provider grants access to documents stored inside another app’s iCloud container. Third-party developers can provide additional document providers by using the Storage Provider extension.
For more information, see the Document Picker Programming Guide. (https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentPickerProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014451)

I think there is something called a keychain access group that does what you want. I've never used it so I'm not real sure about it. Read about it and decide if it will work for you. Some comments I've seen suggest that it's hard to setup and test reliably.
You need to worry about what happens if keychain access needs to be renewed on a user's device after the two apps are installed. How can it be renewed is such a way that they continue to share access to each other's files?

Related

Can I get list of my company's installed apps on device?

I want to know that is it possible in iOS that one could get list of installed applications uploaded by same company?? If yes, then what would be the code???
I know that it's restricted to get list of installed apps in iOS. But I want to know that which of my applications are installed on user's device? So, does Apple allows to get list of own installed apps??
If you did some planning in advance and gave each app it's own URL scheme then you could check if each scheme in turn was openable by the app and count the number that were. But if your apps don't have defined schemes then no, you can't.
Well for the Second part of your question. Yes you can get the list of apps installed in your device using
-(void) allInstalledApp
{
NSDictionary *cacheDict;
NSDictionary *user;
static NSString *const cacheFileName = #"com.apple.mobile.installation.plist";
NSString *relativeCachePath = [[#"Library" stringByAppendingPathComponent: #"Caches"] stringByAppendingPathComponent: cacheFileName];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: #"../.."] stringByAppendingPathComponent: relativeCachePath];
cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
user = [cacheDict objectForKey: #"User"];
NSDictionary *systemApp=[cacheDict objectForKey:#"System"];
}
The systemApp Dictionary contains the list of all system related app and user Dictionary contains other app information.
According to your First part of the question , you cannot directly get the list of apps for a particular company . But You could show a constant URL of the Apple store site to the user in a UIWebView or outside the app in Safari . This URL would have the list of all the apps. Also if you have the list of the URL's your app's loaded on the Apple store . then you could show them individually in the browser too.
no, nothing You ask is possible, of technical and local reasons.
You can see some details only on YOUR devices you configured with IPCU or similar tools, (MDMs..) but not in code.

iCloud base URL null

I have the following piece of code and am trying to access iCloud directory.
(void) reloadFiles{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *containerID=#"KSC75JA957.Dcdmc.TinyPix";
NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil];
NSLog(#"got cloudURL %#", cloudURL);
self.query = [[NSMetadataQuery alloc] init];
query.predicate = [NSPredicate predicateWithFormat:#"%K like '*.tinypix'", NSMetadataItemFSNameKey];
query.searchScopes = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope];
[query startQuery];
}
However, when i run my application I am unable to get the cloud url. And am getting the following errors.
got cloudURL (null)
item update error: 0, Error
Domain=LibrarianErrorDomain Code=10 "The operation couldn’t be completed.
(LibrarianErrorDomain error 10 - Unable to configure the collection.)"
UserInfo=0xce65470 {NSDescription=Unable to configure the collection.}
"Unable to configure the collection" means that Documents syncing is somehow disabled.
Are you signed into iCloud and do you have Documents & Data enabled?
cloudURL will be nil if Documents syncing is not enabled for one of these two reasons.
If cloudURL is nil, you should not attempt to use iCloud.
You sure that you enabled icloud on the device? Refer this:
this is the error that occurs when you haven't enabled iCloud on the device on which you are testing. once i enabled iCloud on the device, the error stopped occurring in my log.
and so now i know what error to check for in order to present the user with a dialog saying "connecting to iCloud won't work until you sign up for iCloud in the system preferences".
You need to enable the iCloud support for your App on the developer portal web site first off all.

GData / YouTube Interface (XCode/ObjectiveC) - Uploading a File and Obtaining the Uploaded URL or videoID

I've been working with the YouTubeTest example a bit to fully understand the GData / YouTube interface and how it uploads files to YouTube.
I've managed to get this to work on my device quite easily but one of the things I wanted to be able to do in my app was, upon completion of the upload, is share the URL of the video I just uploaded to youtube.
URL's are normally of the form :
http://www.youtube.com/watch?v=HRzVPfFIXtY
Would anyone be able to tell me how to find out what the uploaded URL would be or the videoID, as the videoID seems (I think) to be part of the URL (e.g. HRzVPfFIXtY).
Any tips or sample code greatly appreciated.
Cheers
Steve
When your file gets uploaded , function called is below
- (void)uploadTicket:(GDataServiceTicket *)ticket
finishedWithEntry:(GDataEntryYouTubeVideo *)videoEntry
error:(NSError *)error
if (error == nil) {
// tell the user that the add worked
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Uploaded!"
message:[NSString stringWithFormat:#"%# succesfully uploaded",
[[videoEntry title] stringValue]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
}
here VideoEntry is GDataEntryYoutubeVideo type which contains all information about the uploaded video.
I get the url by separating the string.

How to give extended permissions in FBConnect with REST API in iPhone

I have developed an iPhone application, which is communicating data with faceBook. Initially I was only able to get basic information of user from Facebook. To post to a user's wall, I learnt about giving extended permission 'publish_stream', hence I added following code snippet:
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
[self getFacebookName];
}
And made necessary changes in the FBPermissiondialog class file.
Now this is allowing me to post to my wall, but it shows two separate dialogs for permissions, first to access user's basic information, and second for publishing permission. I want to have all permissions in a single pop-up. Also, I am using FBRequest to post to Facebook, not FBStreamDialog (as I dont want the UI for posting).
Please help me with this, I badly need to resolve this issue soon.
Thanks in advance.
In FBLoginDialog.m file
- (void)loadLoginPage {
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"1", #"fbconnect", #"touch", #"connect_display", _session.apiKey, #"api_key",
#"fbconnect://success", #"next",#"user_photos,photo_upload",#"req_perms",nil];
[self loadURL:kLoginURL method:#"GET" get:params post:nil];
}
add "req_perms" key to the dictionary as shown above.
Hope this will solve your problem :)

Cannot get Google Analytics API to register page views on iPhone

I would like to gather usage statistics for my iPhone app using Google Analytics so I'm trying to configure it using the following tutorial: http://code.google.com/intl/fr-FR/apis/analytics/docs/tracking/mobileAppsTracking.html
I think I did everything they indicate in the documentation, and I get no error on the iPhone side, but I don't see any visits in Google Analytics.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self initGoogleAnalytics];
//...
}
-(void)initGoogleAnalytics{
[[GANTracker sharedTracker] startTrackerWithAccountID:[[NSBundle mainBundle] objectForInfoDictionaryKey:#"GoogleAnalyticsCode"]
dispatchPeriod:-1
delegate:nil
NSError *error;
if(![[GANTracker sharedTracker] trackPageview:#"/home" withError:&error]){
NSLog(#"%#", [error localizedDescription], nil);
}
[[GANTracker sharedTracker] dispatch];
}
Any idea why this is not working?
this is the same answer that I put at: Problem dispatching with google mobile analytics for iphone
The Google Analytics stop sending data when you try to send a non formatted "URL", if it is not initiated with the "/" or contain some specific chars, it will start only returning errors.
The best thing to do is, verify that you are placing the "/" on the beginning of you URL and before sending, format your URL to avoid any problem, by doing:
NSString* pageURLString = [pageURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
Encoding it with NSASCIIStringEncoding, will format the URL properly. The same can be used when tracking an event.