I moved from Jane

Original address of this article:The original address

Because of the business relationship of the company, I hope I can survive to do some business operations when iOS is in the background (in fact, it is the background of the rogue to keep alive =. =) was the first to use background positioning to achieve, full of confidence to shelves, the result was apple father hammer head are broken. I was rejected for three times in a row, and the apple representative who applied for a phone call also hammered me, and the appeal for apple review was hammered again. Without further ado, the theme of this blog is that our business is actually very simple, that is, there is business data in the background, the client even in the background also need to process.

Apple can survive in three ways

1. Silent music plays in the background

2. Background positioning

3. Push wake up

Play the music

I passed directly, I think the machine will reject me… Not at all

The background to locate

Just our business vomit excellent pull can also pull on the relationship with the business office place, the first iron is on! Through the background positioning to keep the APP alive, successfully achieved. But by 🍎 dad hammer. Plan two, pass

Push awakening

At this point, there is only one way left. There are two types of push, local push and remote push.

Local delivery

Local push is like a timer that will be triggered when it is triggered. There are many scenarios for alarm clocks or for prompting users to check in. However, according to my tests, the local push stopped when the app was suspended after three minutes in the background. (I don’t know if it was my test, but I didn’t survive.)

Silent push (no voip, some push operation staff is not technical, answer let you do voip, don’t be fooled)

Silent push is actually a kind of remote push. In a tweet, all belong to pass through the message (suggested to have a look at this article) a tweet: what is the ordinary push? What is pass-through messaging? I’m sure this former friend of mine has searched other blog posts without exception.

{
    "aps": {
        "content-available": 1,
        "sound": "com.gexin.ios.silence"}}Copy the code

This thing, but what if I don’t find anything emMM I’m going to say the content-available property again. 0 is not silent, 1 is silent, silent, sound attribute: com.gexin.ios. Silence (I am not sure if other push is the same)

Remember not to write anything, pass the value to the end

Here’s a tutorial for dummies

The preparatory work

1. The push certificate is ready

There are too many tutorials in this section, so just search for one and try it out. Remember to put the exported P12 on a pusher.

2. Turn on the switch

3. Code

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
Copy the code

How to deal with the next is to do your own business processing ~

How to test without background cooperation?

What is a twitter official website used for? Here come, here come, here are two more silly tutorials (content such as the title, if you will not need to see ~)

Go to the twitter website

At this point you should be sure it works. Now it’s even easier to get the background to join in.

If the background is Java

Simple:

payload.setContentAvailable(1);
payload.setSound("com.gexin.ios.silence");
Copy the code

If you also want to pass values, there’s a custom key-value method

payload.addCustomMsg("key"."value");
Copy the code

And we’re done. I wish you a smooth completion of the requirements, do not kill the product manager ~