when and how to detect an iCloud conflict? - iphone

I use iCloud to sync an user xml file between devices in my apps, with a UIDocument subclass, similar to the code from the question:http://stackoverflow.com/questions/7795629/icloud-basics-and-code-sample. but I am not sure when and how should I detect a conflict. I read the sdk doc and searched the internet but didn't seem to find any information with detailed information. it seems we can use some code like
NSNumber* conflicted ;
[url getResourceValue:&conflicted forKey:NSURLUbiquitousItemHasUnresolvedConflictsKey error:nil];
but in my app, it seems always give a true value for "conflicted"?
also I am not sure when should I detect the conflict, my guess is before the contentsForType method of the UIDocument subclass is called. if anyone can give any hint that would be great.

You should observe the UIDocumentStateChangedNotification. If the documentState property of your document has the UIDocumentStateInConflict flag set, there is a conflict. Note that a document can be in multiple states simultaneously, so don't check with ==, instead use something like if (document.state & UIDocumentStateInConflict) {....
You can then get the conflicting versions with the otherVersionsOfItemAtURL: class method of NSFileVersion.
You can find more detailed information in the chapter on resolving document conflicts in the Document-Based App Programming Guide for iOS.

Related

How to clear/invalidate ambient cache on iOS app

When I update tilesets on mapbox, changes don't appear in the iOS app unless I re-install it. There is seemingly documentation on this here: https://docs.mapbox.com/ios/api/maps/5.2.0/Classes/MGLOfflineStorage.html#/c:objc(cs)MGLOfflineStorage(im)setMaximumAmbientCacheSize:withCompletionHandler: but I can't figure out how exactly to implement it. I don't have an MGLOfflineStorage object because I am not worried about offline map storage right now, I just want to refresh the cache in the app. There are good examples of how to do this in android, but not on iOS. Any help is appreciated (preferably in swift)
It appears to be correct to call the methods on the shared MGLOfflineStorage object. The method parameter should be a closure containing any code you want to execute upon completion.
MGLOfflineStorage.shared.invalidateAmbientCache { error in
print("Invalidated")
}
Naturally you should check the error in the usual 'safe' way.

How to get frame data in AppRTC iOS app for video modifications?

I am currently trying to make some modifications to the incoming WebRTC video stream in the AppRTC app for iOS in Swift (which in turn is based on this Objective-C version). To do so, I need access to the data which is stored in the frame objects of class RTCI420Frame (which is a basic class for the Objective-C implementation of libWebRTC). In particular, I need an array of bytes: [UInt8] and Size of the frames. This data is to be used for further processing & addition of some filters.
The problem is, all the operations on RTCVideoTrack / RTCEAGLVideoView are done under the hood of pre-compiled libWebRTC.a, it is compiled from the official WebRTC repository linked above and it's fairly complicated to get a custom build of it, so I'd prefer to go with the build available in the example iOS project; in my understanding it's supposed to have all the available functionality in it.
I was looking into RTCVideoChatViewController class and in particular, remoteView / remoteVideoTrack, but had no success in accessing the frames themselves, spent a lot of time researching the libWebRTC sources in official repo but still can't wrap my head around the problem of accessing the frames data for own manipulations with it. Would be glad for any help!
Just after posting the question I had a luck in finding the sneaky data!
You have to add the following property to RTCEAGLVideoView.h file:
#property(atomic, strong) RTCI420Frame* i420Frame;
In the original implementation file there is the i420Frame property but it wasn't exposed in the iOS project's header file for the class. Adding the property allows you to get view's current frame.
I'm still in search of a more elegant way of getting the stream data directly, without the need to look into remoteView contents, will update the answer once I find it.

iPhone RestKit how to enable RKLogDebug?

I'm trying to debug RestKit object mapping and noticed that there are calls to RKLogDebug throughout the code, but it appears that that macro is undefined somewhere. How can I enable it?
You want to add something like this:
RKLogConfigureByName("RestKit", RKLogLevelWarning);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
to your code. See RKLog.h for the various levels. It is pretty trick.
N.B. this supports a wildcard at the end so, e.g.,
RKLogConfigureByName("*", RKLogLevelTrace); // set all logs to trace,
RKLogConfigureByName("RestKit*", RKLogLevelWarning); // set all RestKit logs to warning (leaving the app-specific log untouched).
– Thanks Kevin!
For Swift user use this syntex:
RKlcl_configure_by_name("RestKit/Network", RKlcl_vTrace.rawValue)
RKlcl_configure_by_na`enter code here`me("RestKit/ObjectMapping", RKlcl_vOff.rawValue)
– Thanks Darshit!
As described in first answer you can configure your app to specific component by calling RKLogConfigureByName.
You can also configure RestKit for specific component using Environment Variables in Xcode scheme. This is useful especially when you have your app building continuously for different environments.
Here's detailed explanation of RestKit logging http://restkit-tutorials.com/logging-in-restkit-debug-tips/

Programmatically retrieve list of installed apps that support a given file type

While it is clear we cannot retrieve a list of installed applications on iOS, are there any tricks to allow us to determine the list of apps registered for a given file type? That is, the list the user will see in the Open In... menu for that particular file type. canOpenURL only returns a boolean, but ideally it would return us a list of supported installed applications.
Open in is certainly possible by the UIDocumentInteractionController You just need to instantiate UIDocumentInteractionController instance:
//Following in header file:
UIDocumentInteractionController *docInteractionController;
Implement the delegate:
<UIDocumentInteractionControllerDelegate>
.m:
//Here the url is the document URL that you want to open (or you want to apply open in functionality)
self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docInteractionController.delegate = self;
Open In method will be like following:
- (void) openIn: (id) sender {
[self.docInteractionController presentOptionsMenuFromBarButtonItem:sender animated:YES];
}
and once you are done:
[self.docInteractionController dismissMenuAnimated:YES];
and that's it. This will list down the list of application supported for document and on selection of them will launch the corresponding application with the document URL we instantiated with.
I doubt either of your two questions ("determine list of apps for a given file type" or "how to implement 'open in...'") is possible in current versions of iOS as users don't see individual files on the home screens that show apps. Nor can an app do a "open a separate app with this specific file" event (which is something easily doable on a Macintosh with Apple Events).
But these do sound like a great feature requests that you can file with Apple at http://bugreporter.apple.com (which you can log into, if you're a registered Apple developers). If enough people ask for these features (and the potential "open in..." functionality is indeed a frequently requested feature), Apple will strongly consider including them in future iOS releases.
You can see this sample program. It might help you. It has used UIDocumentaInteractionController class instance with its property UTI (Unique Type Identifier). It helps in retreving list of installed apps on your phone that support the file type you have opened in your app. You might need to rewrite the UTI property a little bit as per your convience
http://developer.apple.com/library/ios/#samplecode/DocInteraction/Introduction/Intro.html

UIManagedDocument example / tutorial

I have been trying very unsuccessfully to create a simple UIManagedDocument library style application (separate documents saved to iCloud).
I am confused with the following:
Do I subclass UIManagedDocument and set up the persistentStoreCoordinator, ManagedObjectModel & ManagedObjectContext within this subclass, or are these supposed to be configured within the AppDelegate (and if so, how do I go about refreshing the persistentStoreCoordinator to look at the new file - it seems that once that has read a persistentStore that I can't get it to read a new persistent store)?
Richard's example is an excellent example. I used it and the PragmaProg book on core data http://pragprog.com/book/mzcd2/core-data as a guide for creating my managed document module on github.
See: https://github.com/dtrotzjr/APManagedDocument
My code makes use of iOS 7 iCloud Core Data behavior which I cannot comment on publicly until the NDA is lifted. Feel free to ping me directly if you have any questions.
I've just posted a project based on Rick Warren's example: MultiDocumentPlusUUID. In his "Syncing Multiple Core Data Documents Using iCloud" post, Rick writes:
Another bug often shows up when I start trying to pass changes back and forth between devices that both have the same file open. The first sync always seems to work--and it seems to work pretty well as long as each subsequent sync is in the same direction.
MultiDocumentPlusUUID compiles and runs on iOS 7.1b4, and can ping-pong updates to a given document successfully.