My app has an UNNotificationServiceExtension object that exists in a separate project, which handles the receipt and processing of notifications.
I'd like to be able to trigger an event in the main app under certain circumstances, whether the app is active or not. Is this possible? If so, what mechanism would I use to achieve this?
If not, I'm worried that I'll have to use the main app to poll a shared data source when it's activated and respond to the data it reads.
Hmm.. after a bit of googling I found this:
Using URL Schemes to Communicate with Apps
This will allow me to communicate between apps.
Related
This may seem overly ambitious, but I'm exploring the ability to present a view controller from one app in a separate app (both authored by me). I'm not talking about reusing a class, I'm referring to literally presenting a controller from another process over the foremost one.
I believe this is in the realm of XPC on macOS, and how share extensions currently work on iOS. Unfortunately I'm not looking for a share controller though.
Is this at all possible (even using private APIs if I have to)?
Because both apps are sandboxed by iOS, there is no way for either of them to locate and load (something from) the other. Extensions are the only way provided by Apple to have another app perform some action.
Using private APIs will not lift sandbox restrictions. With a jailbroken device, it would be possible to locate the other app. In that case -[NSBundle loadClassNamed:] would allow you to obtain and instantiate a class from a loaded (application) bundle, but it would still be controlled by the process that instantiated it.
So, no, what you ask is not realistically possible for apps that would be distributed to other users than yourself. If it's just for yourself, you might be able to get somewhere with a lot of work on creating, controlling and communicating between processes on jailbroken devices.
If you have your own server, then this is possible. Just have app1 send a trigger to your server, and then your server sends push notification to your app2. when user tap notification, it will open your app2 viewcontroller.
I am building the server side for a calendar application. The client side is iOS only. The original plan was the app will know of iCal event changes then tell the server. But that might be a problem with reminders (via Parse Push). For example, if the event pushed forward the reminder should come earlier.
Is it possible from the server side to be notified on iCal events? For example, when users create/update/delete an iCal event I want to know from a server to grab this information. Is this possible? Or does everything need to be done via a native app thats running?
My server is currently on parse.com. But I could use a separate server say NodeJS if needed.
As iCal is user/device dependent, unless user has synced his calendar events with iCloud. And in second case where user has activated syncing of calendar events, it is completly insecure for end-user to share his icloud details to other server.
How about creating 1 API at backend, which will update/delete requests from Apps for the calendar events, and that will update Parse notification events in background process. For this you can also write customized Parse apis either in NodeJS or any other technology stack.
And in the apps, you can sync the events with iCal using Event Kit:
https://developer.apple.com/library/mac/documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingEvents.html#//apple_ref/doc/uid/TP40004775-SW1
first, you need to able to let iOS wake up your app running in the background, that requires to classify your app to one of the mode stated in the Apple Background Execution, I think the "Background fetch" is appropriate in your case, then in your application:performFetchWithCompletionHandler: you could check the Calendar database for changed events and preform necessary updates to the server.
I think this is your best bet:
https://stackoverflow.com/a/23997912/1967872
In your implementation of the storeChanged: method mentioned in that answer, you should iterate through all the events, detect any changes and submit those to the server.
I don't know exactly that is possible or not but I am thinking it's hard because still I didn't find any library/any features that apple is provides like that.
But I am putting one link that might be helpful for you. Please check it.
http://kb.kerio.com/product/kerio-connect/os-x/support-for-apple-ical-calendar-using-the-caldav-standard-1494.html
I can not use
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
in WatchKit Extension, I have error:
'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
Is there some alternative ?
The short answer is: No there isn't.
The long answer:
Please keep in mind that the extension is not executed on the watch but on your phone. So if you would call UIApplication.sharedApplication() it would return you the application of the extension on your phone, anyway! Everything you do inside your extension is stuff that manipulates the extension on your phone. The only exception from this are the WatchKit methods. And even they are basically calls that are converted into instructions that are send over bluetooth to tell the watch what to do. At no time you can write code that executes on the watch!
You have no control what so ever about what the watch does with the instructions you send to it. You are basically acting as a server talking to a client and you have no control over the client. You should send as little instructions as possible and once you send them, your task is done, the rest is up to the watch.
That being said, you should carefully plan your UI in a way that you do not need any calls that manipulate the event delivery. You should focus on simple 'if user taps x I do y' interaction.
Another thing to keep in mind is, that your extension can not communicate with your main iOS app. You can create a shared app group between your iOS app and your watch extension to share data between them, however you can not directly communicate with your app. If you want to use parts of your apps logic, extract the module in question into a framework (this has become very easy with Xcode 6) and use the framework in both, your app and your extension.
I have two apps with same UISupportedExternalAccessoryProtocols. These are communicating with the MFI certified device. How I can know that the session is already created with other app on the same device. So I can alert to the user that you can't create multiple sessions with the same accessory at a time.
Please help to fix this.
Thanks in advance.
I personally consider AyBayBay's answer invalid, since you tagged your question with the "iOS tag" and NSDistributedNotificationCenter is not supported on this platform. (There is a low level api to do this, but I think it's in a private framework)
If you are pretending to target your app to iOS8+, the simplest way to do it is using iOS8's AppExtensions feature. I made some tests creating a session within my app, and sending info to the device from another app using extensions the way below.
some app -> app extension -> my app connected with ext.device -> ext.device
so I'm pretty sure you can check if the session is opened or not and return this info to the caller app.
FYI: To pass info to another app you can also use URLSchemes or UIPasteboard too, but both behaviours in a different way than AppExtensions and I think it not fits on your case. Maybe it helps someone else...
Well when one app connects and establishes a session with your MFI device, you can post a notification to NSDistributedNotificationCenter. Your other app can subscribe and listen for this message, upon recieving it and processing it in its runLoop (when it comes back into the foreground) you can have code that blocks it off from creating a session at the same time. You will have to experiment with this a bit but it can be done.
I have a phonegap app and I want to execute Javascript code in a background task. When the application enters background I start executing a javascript function which takes data out of a web database and sends some values to a web service, the returning data may toggle a push-notification to the user.
I found either how to call javascript from Objective-C here on Stackoverflow and how to implement Long-Running Background Tasks in the iOS SDK Documentation pages, but I haven't found anything in combining both (what I think is e.g.: When I invoke javascript code via a webview, does this View even exist when the App is in background?) so I want to ask some more experienced iOS Developers if this is even possible.
I don't think its really possible. Javascript requires a UIwebview to run (in realtime) and must be visible to the user. When an app is put in background only a small amount of tasks are allowed to run- webview not one of them.
Your better off sending your data to a web server that runs a cron-job or similar to send out a push notification via apples push notification server - You can also bypass this and use a service like http://urbanairship.com/
I experimented with this on iOS 5+ and it's possible. I created a small PhoneGap plugin that demonstrates how this works. Check it out, and see the README for most of the info.
https://github.com/jocull/phonegap-backgroundjs