Today Extension (App Groups) - ios

I have been browsing the Apple Documentation for hours now and there is so little on the Today Extension, so I just can't get to the bottom of this problem...
I am trying to access a plist file stored in the NSDocumentDirectory but am having no luck. The today extension is all set up correctly with a separate target in the project and my bundle identifier starts with 'group.' but I get a null value every time?
This is my code...
NSURL *storeURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:#"group.com.ORGANISATION.APPNAME.wigit"];
NSString *string = [storeURL.path stringByAppendingPathComponent:#"DataFile.plist"];
NSMutableArray *content = [NSMutableArray arrayWithContentsOfFile:filePath];
Thank you for your help in advance!

If I understand your question correctly, you are trying to share data between the AppExtension and the containing app. By default your extension and its containing app have no direct access to each other’s containers. So the NSDocumentDirectory of your app will not be accessible form the extension. You could use NSUserDefaults to share the data.
Read it here Sharing Data with Your Containing App

Related

Sharing file/data between two iOS apps that I own

I have apps A and B and both are developed by me. I want to send file from A to B but it has to happen without using any sharing services like dropbox or anything that involves internet connection.
OpenURL/CustomURLSchemes doesn't seem to work since you are limited with the data you can pass and the file size can be big. And because of the sandboxing I can't write the file and pass the url...
UIActivityViewController and UIDocumentInteractionController are options only if there is a way to display just one app which I fail to achieve so far..
Is this possible?
I own both apps and the file extension is custom.
You actually don't need extensions to share data between your own apps. You can use app groups for this.
In both MyApp1 and MyApp2 goto the target, then capabilities, then click on the app groups capability. Let Xcode help you get app group entitlement setup in your apple developer account.
Now you can use that app group ID to share data between you apps. For instance:
In MyApp1 put this in your appDelegate:
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.mycompany.myappgroup"];
[myDefaults setObject:#"foo" forKey:#"bar"];
And in MyApp2 appDelegate put this:
NSUserDefaults *myDefaults = [[NSUserDefaults alloc] initWithSuiteName:#"group.mycompany.myappgroup"];
NSLog(#"Show me something: %#",[myDefaults objectForKey:#"bar"]);
Make sure that the string you used for the suite name is the exact same as what is under the app group capabilities section in Xcode and also the string in your entitlements plist that was automatically added to your project.
You can also share files using the same idea:
NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:
#"group.mycompany.myappgroup"];
And for those of you who want to see it in Swift:
var userDefaults = NSUserDefaults(suiteName: "group.mycompany.myappgroup")
var fileManager = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.mycompany.myappgroup")

Unable to open my excelSheet in MS-Excel iOS app from my iOS app via url scheme

Actually I am following this document to open my excel sheet in iOS MS_EXCEL app from my app via url scheme.
By using its documentation I open EXCEL app successfully. But I am totally unable to open my excel sheet . Every time EXCEL app gives me error showing in this image
I am passing my saved file url to Excel app. I have checked the saved file path by iExplorer. That file is perfectly opened . But in Excel app, its really giving me headache.
Please help me out that where am I making Mistake.
Here my code snippet
static NSString * encodeByAddingPercentEscapes(NSString *input) {
NSString *encodedValue =
(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef)input,
NULL,
(CFStringRef)#"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedValue;
}
-(NSURL*)excelUrlStringForFile:(NSString*)urlFile WithContext:(NSString*)strContext
{
NSURL *result =[NSURL URLWithString:[[NSString stringWithFormat:#"ms-excel:ofe|u|%#|p|%#|c|%#",encodeByAddingPercentEscapes(urlFile),urlScheme,strContext] stringByAddingPercentEscapesUsingEncoding:4]];
return result;
}
Here If I am not using 'encoding string by NSUTF8StringEncoding'
this above NSURL object result is set to nil. So I must have to use encoding.
NSURL *openExcelURL = [self excelUrlStringForFile:filePath WithContext:str_fileName];
if([[UIApplication sharedApplication] canOpenURL:openExcelURL])
{
[[UIApplication sharedApplication] openURL:openExcelURL];
}
I am in the same situation, I'm trying to open local files from other application, looking into the website where you have seen the excel URL Scheme I found this text. It looks like you cannot open local files using this method, it is very strange but only it makes reference to OneDrive and SharePoint files... =S
If someone knows something about this issue would be very useful to us
You can enable users who are running Office on an iOS device to open and edit files stored in SharePoint or OneDrive from any application, and then quickly return them to the original application when they’re done editing the file. To do this, you pass files to Office via protocol handlers, and you make sure that Office is invoked in a way that Office can understand.

FileURL gets invalid each time I rebuild the application or install a new version

I'm saving videos and audio files I'm recording in the application I'm working on. Here's an example of a URL part:
#"file:///var/mobile/Containers/Data/Application/1AADB360-ABA7-493E-AE35-290803AA2EBD/Documents/444571753026.caf"
If I rebuild or install a new version from testflight, the application doesn't find the file, and if I save another one, the bold part of the URL has changed. How do I handle this? Keep in mind I already have a version of this app on the appstore and it would be preferred if I could update the app without the users losing their data.
That identifier can change and there are no guarantees that it will always remain the same. iOS SDK provides relevant API's so that you do not have to depend on that and always get the correct path to the Documents Folder. You can use:
NSURL *directoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
This will give you the URL for the documents directory for your app. For further exploration inside the directory:
NSFileManager *fm = [NSFileManager defaultManager];
NSDirectoryEnumerator *enumerator = [fm enumeratorAtURL:directoryURL includingPropertiesForKeys:#[ NSURLNameKey, NSURLIsDirectoryKey ] options:NSDirectoryEnumerationSkipsSubdirectoryDescendants|NSDirectoryEnumerationSkipsHiddenFiles errorHandler:NULL];
In case you know the file or folder's name, you can use:
NSURL *fileURL = [directoryURL URLByAppendingPathComponent:directoryName isDirectory:NO];
You can configure the enumerator according to your requirements to perform as you desire. This is only a sample that I am using in one of my apps.
You can replace NSDocumentDirectory with NSCachesDirectory or NSLibraryDirectory if you require access to those.

Update newsstand cover art without updating content

I have added a new issue with a new cover art. But it is not appearing in the newsstand shelf. I don't want to update my app. How long will it take for the new cover art to appear on the newsstand shelf? Should I add a new version of the app to update the cover?
You don't need to update your application. You need to send a push notification with a very specific format.
The details can be found in the Newstand FAQ found
How is the push notification that initiates the Newsstand background download different from other push notifications? Will I have to change or modify my backend infrastructure?
It appeared today in the newsstand, it was just the matter of time. Thank you all!
You can use some URL to get cover image. And when it is necessary to change cover, you can just change the image on that URL. For example:
NSURL *getURL = [NSURL URLWithString:#"http://youURL/main.png"];
ASIHTTPRequest * getRequest = [ASIHTTPRequest requestWithURL:getURL];
[getRequest startSynchronous];
NSError *error = [getRequest error];
if (!error) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:#"main.png"];
NSData* responseString = [getRequest responseData];
[responseString writeToFile:filePath atomically:YES];
UIImage *result = [UIImage imageWithContentsOfFile:filePath];
UIApplication *app = [UIApplication sharedApplication];
[app setNewsstandIconImage:result];
}
Everytime you only need to change image on http: //youURL/main.png. That is all.
I used here AsiHTTPRequest to download the image.
It is clear from several sources including Apple’s own specification that the atom feed in newsstand is used for updating the App Icon and description found on the app store only and not used for updating the app icon in the newsstand folder on the device.
https://itunesconnect.apple.com/docs/NewsstandAtomFeedSpecification.pdf
"Newsstand is a feature of iOS 5 that allows your readers to access the latest issue of your newspaper or magazine. You host your content on your web server and provide the App Store with an Atom feed that provides updated metadata and cover art for each issue as it becomes available. The Newsstand Atom Feed XML (described in this document) is used to enable the App Store to display your app with the cover art and metadata that is relevant to the latest issue.
This document specifies the Newsstand Atom Feed XML format for managing Newsstand issue metadata.
Newsstand issue metadata is displayed on your Newsstand app’s product page in the App Store. The metadata provided should accurately reflect the issues and content that are available within your app.
Newsstand issue metadata can be managed via the Newsstand Atom Feed or directly in iTunes Connect. The
Newsstand Atom Feed allows you to create new issues and update existing issues. The Newsstand Atom Feed
is processed daily. The Newsstand Atom Feed is based on the Atom 1.0 format."

storing files on iCloud and distributing them to all app users

I am building a iOS 5.1 app using storyboard. this app contains a table view. My idea was to add an "add" button to my title bar, in the table view. When a user clicks on the add, a simple document editor I need to build (like keynote or pages) will open. when the user clicks on the save button, the file will be uploaded possibly on I cloud, and all other users of the application will be able to access it, from a downloads tab, download it, and add it to their own app (a sort of file sharing via iCloud). Is it possible to do something like that? How can I do it? Can I do it using iCloud, or do i need to build my own database?
maybe you should try to use this:
NSURL *urlToShare = ...; NSDate *date;
NSError *error;
NSURL *sharedURL =
[[NSFileManager defaultManager] URLForPublishingUbiquitousItemAtURL:urlToShare
expirationDate:&date
error:&error];
Thats from CS193p lessons. This code will help you to share files between different iCloud Accounts.
But remember that "Only files (not directories) maybe exported in this way.
The URL points to a copy of the file (so it is a read-only sharing mechanism)."
Hope this helps!

Resources