简体   繁体   中英

iPhone push notifications information

Is it possible to transfer any information in the push notification beside "badge" "sound" and "text" ?

For example, in the app "whatsapp" when a push notification appears and pressed, the app is opened but not going to the conversation. My guess is that it can't know what conversation to go to. But then I saw that in facebook messenger app it actually goes in the conversation. how does the messenger app know that what conversation to go to?

Also, if it is possible to transfer information, why is it that apps like whatsapp don't use it and also ask you for your name so it will be displayed in the push?

Yes, indeed. But your message size (in bytes) must not pass a certain threshold Apple has imposed. You can then pull that info in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions using something like this:

NSDictionary* dictionary = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

Where dictionary contains your push notification info.

There are apps that have permission to run in the background and other apps that have not. May be facebook messenger app have this permission and can receive push notifications and do whatever is needed to go to the correct conversation or user. I don't know if this is true but it could be a possible reason.

in this method we can display pushnotifications alerts and their action according to our app

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo   
{


    NSLog(@"did receive remore notification %@",userInfo);
    if(isForground)
    {
    }
}

You should take a look at this documentation section Examples of JSON Payloads

At the bottom you can see custom payload examples like:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

Where acme1 and acme2 are custom data that you can pass to the push notification and get it inside you app after launched.

The data is available through UIApplicationDelegate callbacks as described here Handling Local and Remote Notifications

You can add more arguments in your payload. In our app we add something like groupID, or type. See this stack overflow for adding more payload arguments

APNS JSON PAYLOAD - more arguments

确保消息大小不超过256个字节。这是有效负载的阈值限制

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM