3

My first app (lets call it CoreApp) works in background. When this CoreApp receives silent push notification I would like to pass data to my second app (UiApp). Custom url scheme is not an option here because:

  • [[UIApplication sharedApplication] openURL:url] returns NO when CoreApp is in background.
  • If I open via url scheme, UiApp moves to foreground, but I want to keep it in background.

I am thinking of adding voip key to both apps and communicate through sockets.

Any other ideas? Both apps are not for appstore, so I am able to use any hacks.

EDIT

The goal is to increase badge number of UiApp when CoreApp received notification. So, I want pass simple int number from CoreApp to UiApp.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sergey Demchenko
  • 2,924
  • 1
  • 24
  • 26
  • 1
    If your case is as simple as increasing badge number then try Darwin notification center https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFNotificationCenterRef/Reference/reference.html . It can't send data but you could send multiple notifications to increase the number more than by one. – creker May 14 '14 at 14:18
  • Is the UiApp **running** in the background, or suspended? This makes a difference. – Nate May 15 '14 at 04:04
  • @creker, thanks for the answer I am playing with it now. – Sergey Demchenko May 15 '14 at 07:24
  • @Nate it is suspended. But as I know, any background app (even voip) is suspended until it is wake up for some period of time. – Sergey Demchenko May 15 '14 at 07:50
  • So, you need to wake up the UiApp, **and** then also pass data to it? Or is this question only about how to pass data to it? – Nate May 15 '14 at 07:56
  • @Nate the question is how wake up UiApp and pass data to it, but not move UiApp to foreground (the main goal, as I sad above is increase badge number of UiApp from CoreApp, even if UiApp is killed). – Sergey Demchenko May 15 '14 at 08:00
  • @Nate: I think you should post it as an answer – Victor Ronin May 15 '14 at 15:22

4 Answers4

2

First of all, take a look at my question regarding sharing data between apps: Sharing info between multiple iOS apps

If I were you, I would go with pasteboard or sockets.

On top of that, you may be interested to look at private API:

SBSetApplicationBadgeNumber(mach_port_t* port, char* appID, int number);

It was not protected by entitlement and you was able to set a badge on another application.

Community
  • 1
  • 1
Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • thanks for answer. I can not find SBSetApplicationBadgeNumber documentation... Which header should I include in order to use this function? – Sergey Demchenko May 15 '14 at 09:01
  • @SergeyDemchenko, that function isn't in any actual (documented) header. You can just create your own header file, and put the declaration Victor showed in it. Then, make sure your app links against the SpringBoardServices.framework, which is where that symbol is actually defined. However, calling this method, I don't think, will actually wake the other app up. – Nate May 15 '14 at 09:11
  • @SergeyDemchenko: The only reason why I mentioned this undocumented function is because you posted in privateapi tag. – Victor Ronin May 15 '14 at 15:21
1

A solution, but I don't know if it can be of any use for you (please indicate what kind of data you want to share to the second app, what you want to do with it in this second app, and more especially: WHEN you need to have your second app work with this data)

Take a look at UIPasteboard,

+ (UIPasteboard *)pasteboardWithName:(NSString *)pasteboardName create:(BOOL)create

to create a pasteboard to be used by both your applications (you would probably want to set the persistent property to YES).

You can then use addItems: method to add elements to this pasteboard. When you launch your second application, it could look the content of the pasteboard, use it and then remove it.

Jerome Diaz
  • 1,746
  • 8
  • 15
  • I want to update badge immediately, so unfortunately UIPasteboard is not an option too... – Sergey Demchenko May 14 '14 at 14:17
  • @SergeyDemchenko, UIPasteboard will work for you, but you have to send your own notification, letting the other app know that the pasteboard has changed. The normal `UIPasteboardChangedNotification` doesn't seem to get transmitted while in the background, so you need to use your own custom notification, and **then** check the pasteboard for new badge number data. – Nate May 15 '14 at 09:15
0

Whenever the CoreApp received a remote push notification, call a url on background to the server, the server then increase the badge number and send out a remote push notification (with the new badge number) to UiApp.

Hao
  • 134
  • 4
  • thanks for answer. Yes it is a solution, but it requires addition communication with server. I am trying to find solution how to communicate between apps locally. – Sergey Demchenko May 14 '14 at 14:29
0

I decided to use 2 voip apps and communicate via sockets.

Function:

SBSetApplicationBadgeNumber(mach_port_t* port, char* appID, int number);

is not available on ios7 and I didn't find new api similar to this.

Darwin notification center & UIPasteboard works perfect when UiApp is in foreground, but when app is suspened Darwin notification are not received.

Sergey Demchenko
  • 2,924
  • 1
  • 24
  • 26
  • 1
    You could still do it using notifications. You just need to keep your app running while in background. This can be done by looping audio file. But voip and sockets will probably work better in your case. – creker May 17 '14 at 17:24