iCloud base URL null - iphone

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.

Related

App still saves data to iCloud even if it's turned off

I've made it possible to show inserted data on other devices through iCloud, but even when I turn iCloud off for my app (Documents&Data -> My App Off), after a few seconds the entered data appears on the other device (which has iCloud enabled) also.
Does this mean that even if
- (void)initializeiCloudAccessWithCompletion:(void (^)(BOOL available)) completion {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL * _iCloudJuurkataloog = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (_iCloudJuurkataloog != nil) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"iCloud available at: %#", _iCloudJuurkataloog);
completion(TRUE);
});
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"iCloud not available or the app is running in simulator");
completion(FALSE);
});
}
});
}
returns "iCloud not available", it is only informative message and I have to control saving to iCloud manually, because if I won't the data will be saved anyway?
Edit:
It seems that when turning iCloud off from Documents&Data under Documents&Data (I guess it turns iCloud off for all apps as it says "Allow apps to store documents and data in iCloud" for enabled mode), everything works as expected - NSUbiquityIdentityDidChangeNotification is received and I won't be able to send any data to iCloud or receive any data from iCloud.
But when turning off iCloud for specific app (Documents&Data -> My App Off), NSUbiquityIdentityDidChangeNotification is not received, URLForUbiquityContainerIdentifier returns nil as if iCloud isn't available, the app can still send updates to iCloud, BUT it won't be able to receive them.
Am I getting something wrong or is there a reason to believe that this is the Apple bug?
By the way, when toggling the iCloud switch for specific app while running from Xcode on a device, I get a SIGKILL - maybe a Xcode bug?

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

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?

Getting error ACErrorPermissionDenied (error code 7) for Facebook when using Social Framework

I am fetching the user’s Facebook account ID and name using ACAccountStore.
When an alert comes up asking the user for permission (“XYZ would like to access your news feed and profile”) and the user taps on “Don’t Allow”, I get error code 7, i.e ACErrorPermissionDenied.
But after that, if I go to Settings and switch on the Facebook settings for my app and back in the app the alert pops up again and the user taps on “OK”, I’m still getting error code 7 (ACErrorPermissionDenied). So it’s enabled in Settings and I’ve tapped “OK” in the app, but it’s still giving me this error.
If the first time I allow access and after that switch access on or off from Settings, it gives me the proper error or success. This problem occurs only if the user taps “Don’t Allow” the first time. If he doesn’t allow it in the app when it asks, then he will not be able to allow FB access to my app.
I’ve tested this on iOS 6.0 and 6.0.1 using the following code:
NSMutableArray *acAccountArray = [[NSMutableArray alloc] init];
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType =
[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore
requestAccessToAccountsWithType:accountType
options:[self getOptionDictionary:ACAccountTypeIdentifierFacebook permission:[[NSArray alloc]initWithObjects:#"read_stream",#"user_about_me",#"email", nil]]
completion:^(BOOL granted, NSError *error) {
if(granted) {
// Doing what I want
} else {
NSLog(#"Error: %#", error);
}
}];
-(NSDictionary *)getOptionDictionary:(NSString * const)accountTypeIdentifier
permission:(NSArray*)permissionArray {
NSDictionary *options = nil;
if (accountTypeIdentifier == ACAccountTypeIdentifierFacebook) {
options = #{
#"ACFacebookAppIdKey" : #"dhksadhakjdhkshd",
#"ACFacebookPermissionsKey" : permissionArray,
#"ACFacebookAudienceKey" : ACFacebookAudienceFriends};
}
return options;}
Is your app still in "sandbox mode" on Facebook? If yes, it will be visible only to administrators and developers. If you're logged in to Facebook on your device with a non-administrator for your app, you might receive this error. Disabling the sandbox mode fixed the problem for me.
This is because you have removed your app in facebook, even i am facing same problem. If you try to login using any method other than iOS native login then it adds facebook app if it is not there or removed by the user in facebook settings but it is currently not happening if you try to login using iOS native login.
Please inform me if you come across ant solution for this issue and also is their a way i can remove my app being listed in iOS facebook settings in this case because if i remove and then user retries for login then it works correctly.

Does URLForUbiquityContainerIdentifier: return nil when network access is not available?

When in airplane mode or any other state where network access is not available, will a call to NSFileManager's URLForUbiquityContainerIdentifier: return nil?
A follow up question to this is: if this call to URLForUbiquityContainerIdentifier: DOES not return nil but rather returns a valid URL when network access is not available is this a way to access cloud based documents offline?
The apple docs state that this will return nil if iCloud is not configured or not enabled. It does not mention what will happen if network access is not available.
I would test this myself but from what I understand I would have to test this on an actual device and testing on a device is not possible for me at this time. Thank you!
The UbiquityContainer is a local storage container that contains the documents you requested from iCloud. This container is available when when the network is not. By using the following example
NSURL *ubiq = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSLog(#"iCloud access at %#", ubiq);
// TODO: Load document...
} else {
NSLog(#"No iCloud access");
}
You will be able to access the files and ubiquity container when the phone is even in airplane mode. When the network connections restore the icloud daemon will automatically sync the files even in the background.
Here is a great article on iCloud setup.
http://www.raywenderlich.com/6015/beginning-icloud-in-ios-5-tutorial-part-1

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.