Getting images in WatchKit app from iOS app - ios

I'd like to show in a WatchKit app the user's avatar image from its paired iOS app. Such image is downloaded by the iOS app querying a REST web service when the user logs in the app. How could I get it from the WatchKit app?
The downloaded avatar is persisted as a .jpeg file in the Documents folder of the iOS app.

The easiest way to solve your issue is to write the avatar image out to the App Group directory instead of the Documents directory in the iOS app. Then you can load the avatar image from the App Group file system directly from the Watch Extension. In order to do this, you'll need to make the following changes.
Step by Step
Add an App Group to your iOS app and Watch Extension
Write the avatar image to the App Group instead of the Documents directory
Read the avatar image out of the App Group in the Watch Extension
Push the avatar image into the WKInterfaceDevice shared image cache
Apply the image to either a WKInterfaceImage or WKInterfaceGroup to be displayed
Hopefully that helps make things a bit more clear.

Related

Load stickers from the Server and show in iMessage app

I am starting work on a Sticker pack application. I created a new project and selected the iMessage application.
My requirements are:
Download the stickers from the Server and show them in CollectionView.
The user should tap on the Sticker and add it to the chat thread.
After googling many solutions I see that for sending stickers, it is necessary to set path of the image and localized description. But when we fetch the images from server we only have image server path.
How i send the sticker via local path?
You can´t do that. Stickers have to be in the App Bundle. The bundle can´t be changed from within the App.

Apple watch multiple Assets.xcassets folder purpose

What's the difference between the Assets.xcassets in
1) WatchKit App
2) WatchKit Extension
I'm not sure which folder should I place the image in.
I need to access the image (e.g. testImage.png) in both Interface.storyboard which resides in WatchKit App folder and in WatchKit Extension. In the controller I'm setting it using:
let menuIcon: UIImage? = UIImage(named: menu.iconName)
I've tried:
Option 1:
1) to place images in both WatchKit App and WatchKit Extension
Which will mean duplicate images, in two Assets.xcassets folder.
Option 2:
1) to place images in both WatchKit App only and change the target membership of the Assets.xcassets to support both WatchKit App and WatchKit Extension
Which approach is better? or are there any better ways?
This seems to be a holdover from watchOS 1 when the WatchKit Extension was actually running on the iPhone and sending information and resources to the WatchKit App running on the watch.
There are some calls which will work only with the WatchKit App's Assets.xcassets folder such as setImageNamed: or setBackgroundImageNamed:
There are several ways to change the current image of an interface object:
Use the setImageNamed: or setBackgroundImageNamed: methods to assign an image that is already in the Watch app bundle.
Use the setImage:, setImageData:, setBackgroundImage:, or setBackgroundImageData: >methods to transfer image data from your WatchKit extension to your Watch app.
Specifying images by name is more efficient because only the name string must be transferred to your Watch app. watchOS searches your Watch app bundle for an image file with the name you specified. The most efficient way to specify images efficiently is to store them in your Watch app bundle and use the setImageNamed: or setBackgroundImageNamed: as appropriate to configure the corresponding object.
Images created in your WatchKit extension must be transferred to the Watch app before they can be used. For example, using the imageNamed: method in your extension loads the image from your WatchKit extension’s bundle, not from your Watch app’s bundle. You can then call the setImage: method, passing in the image object. The WatchKit extension automatically transfers the image to the Watch app for display. While this has some additional overhead compared to loading images directly from the Watch app bundle, It should not have a significant impact on either performance or battery life.
App Programming Guide for watchOS / Images
Personally I would not place images in both folders as this will increase the size of your App. I tend to place images that will be set by Storyboard in the WatchKit App's folder and all the images that will change programmatically in the Extension.

How detect changes in the application documents directory in iOS app?

I am currently working on an app with the file sharing feature.
We have a view to ask the user to plug his device to iTunes to add files if there is no files in the app.
I would like to remove this view when the iOS app is launched on the device and when the user add at least one file with iTunes to the app.
Is there a way to do that with the default FileManager ? Like a delegate or something to detect events from the document directory of the app ?
I have looked on the web and found some pods but only for macOS.
I have also tried something with a Timer which will get the files from the document directory of the app each 0.25 seconds, but I don't think this is the best way to do what I want.
Thanks for your help.
EDIT:
Thanks to the MartinR's comment below, the following link helps me to do what I wanted
Notification if user modifies contents of documents directory via iTunes File sharing

ios 7 background sync uploading pictures

I have studied the background syncing and multitasking capabilities of iOS 7. What cant figure out is the possibility to upload new photo's taken with the camera app.
The part to upload a file in the background isnt the hardest part, but what delegates do i have to use to detect wether a photo is taken and upload this particular latest photo?
Possible duplicate: iOS - Background uploading of photos
I think you can use Photos Framework to do it. There is a delegate method to callback if one photo is edited or added.
First Photos Framework only supports iOS8+;
#import Photos;
Implement PHPhotoLibraryChangeObserver protocol;
- (void)photoLibraryDidChange:(PHChange *)changeInstance {
if (![collectionChanges hasIncrementalChanges] || [collectionChanges hasMoves]) {} else {}
}
If I understand correctly, what you want to do just cannot be done on iOS (Apple security limitations).
If you want to upload a photo each time user takes a photo with Camera app (the OS built in Camera app), you would have to implement something such as folder scanning, to detect there is a new image in Photos folder. That would require access to complete file system, including files of all applications, which cannot be done due to Sandbox restriction.
In iOS, each application has it's own directory and you are allowed to write only to that directory. Access to files outside of it is always rejected (unless you are super user on a jailbroken phone).
Read more about iOS Sandbox:
https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/TheiOSEnvironment/TheiOSEnvironment.html
https://developer.apple.com/library/mac/documentation/security/conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html
What is Sandbox in ios , Can i Trans data between in one App to Another App in iPhone,if possible how
So what you can do on iOS, is to open a Camera picker view and allow the user to take a photo. After that you can easily access the photo and upload it to your server. Read more about it on the links below:
opening camera in iphone app programatically
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html

ios using itunes to upload an image to app

how can I have itunes uploading an image to the directory of my app on iOS
like user selects an png from her computer and upload that image to the file system sandbox of the app
thanks!
The feature you're looking for is called 'iTunes File Sharing'. With some googling you will be able to find plenty of tutorials about this, such as: http://www.raywenderlich.com/1948/how-integrate-itunes-file-sharing-with-your-ios-app

Resources