简体   繁体   中英

Is there a way to send user-specific push notifications for iOS devices?

I would like to know if I can create a service to send customized user-specific push notifications for iOS.

Example

@"Hey %@, how you doin", firstName"

Is this possible?

Unless I completely misunderstood what you need, no answer has what you need.

Here's a relevant example from the APNS guide :

let's consider an example. The provider specifies the following dictionary as the value of the alert property:

{ "aps" : 
  {
    "alert" : {
        "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
        "loc-args" : [ "Jenna", "Frank"]
    }
  }
}

When the device receives the notification, it uses "GAME_PLAY_REQUEST_FORMAT" as a key to look up the associated string value in the Localizable.strings file in the .lproj directory for the current language. Assuming the current localization has an Localizable.strings entry such as this:

"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";

the device displays an alert with the message “Jenna and Frank have invited you to play Monopoly”.

Of course. Check out the APNS programming guide, specifically the payload, which you can customize on your server before you send it to the user's device.

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

Also note that if you know when the notification should appear (not at a dynamic time) then look into local notifications, which don't require a server backend.

There are some very good solutions for iOS push notifications service that use APNS. No need to implement it on your own.

  • PushApps - free for 1M notifications per month, and unlimited notifications for 19.99 per month, and you can import your users via the API or by sending the a csv file - documentation
  • Urban Airship - free up to 1M notifications per month, afterwards you are charged per 1000 notifications
  • Parse - also free for the first 1M notifications
  • PushWoosh - free for 1M devices, premium plans are from 39 EURO

If you have to implement it on your own, have a look at easyAPNS if you want to host it yourself.

Another good site for info is Ray Wenderlich's site which hosts a 2 part tutorial:

Or this , Apple Push Notification module for Node.js.

You can use any service for Push Notification (as listed) or do it by yourself.

In your code, when you receive the Push Notification message:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"Received notification: %@", userInfo);
    //here you should treat your received data
}

Of course you can...

You need to create your own back-end php file for push notification service, you can send json data from your app to the php file and use $GET to achieve the data you want, including device token, message, badge number... please refer to this

in your viewController

NSString *finalUrl =[NSString stringWithFormat:@"%@/pushService.php?device_token=%@&passphrase=%@&msg=%@",baseURL,device_token,passphrase,msg];
NSURL *url  =[NSURL URLWithString:finalUrl];
NSData *jsonData = [NSData dataWithContentsOfURL:url];

if(jsonData != nil)
{
    NSError *error = nil;
    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSLog(@"result: %@", result);

}else
{
    NSLog(@"connection error!");
}

pushService.php file

// Put your device token here (without spaces):
$deviceToken = $GET['device_token'];

// Put your private key's passphrase here
$passphrase = $GET['passphrase'];

// Put your alert message here:
$message = $GET['msg'];

$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'badge' =>  5 
);

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