I am planning out a Mac OS X (Lion) application and wanted to ask some questions about APNs.
First off: Can you send APNs to a Lion Application that is something other than a Badge or Alert? That is, can you perhaps send a key/value pair or some such data to the end-point application that it can use to determine what action to take? Pretty sure I could do this in iOS land but not for Mac OS X
Will the application that receives the event be able to do so - even if it's in the background?
Lastly, does the application need to have a UI? i.e. can I write a back-ground only application that can be the end-point for the notification?
What I really am trying to work out is if I can leverage APNs on Lion as general purpose mechanism for alerting my application to do something or if it's purely for delivering UI alerts?
You can only register for badge alerts (NSRemoteNotificationTypeBadge) but you can send the same payload type as in iOS and the Mac app will receive it. So far I've only managed to get running and background apps to receive the notification, but the docs say:
Mac OS X Note: Because the only notification type supported for
non-running applications is icon-badging
So it seems like non-running apps should be able to get the notification, but I haven't figured that out yet.
Here's my app receiving a notification in the background:
2012-02-13 18:00:39.531 TestPush[25580:707] Received Push Alert: TESTING
2012-02-13 18:00:39.532 TestPush[25580:707] Received Push Badge: 10
2012-02-13 18:00:44.153 TestPush[25580:707] applicationDidResignActive
2012-02-13 18:00:57.233 TestPush[25580:707] remote notification: {
"_" = "n7dBZFYpEeGiNBT+tdMfCA";
aps = {
alert = TESTING;
badge = 10;
};
}
Here's a custom payload (key/value pairs that you mentioned):
2012-02-13 18:23:44.665 TestPush[25958:707] remote notification: {
"_" = "zsUPTFYsEeGiNBT+tdMfCA";
acme1 = bar;
acme2 = 42;
aps = {
alert = "You got your emails.";
badge = 9;
sound = "bingbong.aiff";
};
}
2012-02-13 18:23:44.666 TestPush[25958:707] Received Push Alert: You got your emails.
2012-02-13 18:23:44.666 TestPush[25958:707] Received Push Sound: bingbong.aiff
2012-02-13 18:23:44.667 TestPush[25958:707] Received Push Badge: 9
2012-02-13 18:23:44.667 TestPush[25958:707] Received cust1: bar
2012-02-13 18:23:44.668 TestPush[25958:707] Received cust2: 42
Not sure about the UI part, I wouldn't have thought you need a UI though.
Also check out this sample code from Apple PushyMac.
Related
I'm trying to send a notification via C# SDK. I'm sending notifications for iOS.
string payload = "{\"aps\" : { \"alert\" : \"Message received from Bob\" }}";
var outcome = hub.SendAppleNativeNotificationAsync(payload, new[] { "b6a5d9c3-4297-422f-9a8d-b7979c30a5f8" }).GetAwaiter().GetResult();
Registration works fine, I can retrieve registered users, but I receive errors on sending. The error message is
Contract mismatch between ServiceBus and the Push Notification System
I've looked into manage.windowsazure.com for monitoring and saw that there were errors of type “Bad channel error”.
I assume that I should try to change my region for NH and probably the problem will go away, but is there anything else I could look at to resolve this issue?
Forgot to mention that everything was working on the first day I started to work with push notifications and only after several days became broken without any changes.
you may have open port 2135 and also add APN certificate
I didn't figured out what does that error mean but at least found the root cause. It was Testflight that by some obscure reasons uses production gateways to send notifications and not sandbox, and my NH has been configured with sandbox certificate, that's why it didn't work.
I am configuring push notifications on for iOS using Xcode 7 and Parse. The notifications are working perfectly on a device running iOS 9.
But when running the application on a device with iOS 8, I am running into problems. I am unable to get the Alert View where the user can select to "Allow Notifications from App X".
But, the device token registration call is being called successfully when the user opts in to push notifications and the device is successfully registering an Installation object with a valid device token. Notifications are also being sent to the device.
If I go into Settings->Notifications->My App and turn the Notifications On or Off, it doesnt make a difference the notifications are still being sent through.
This is the code I am using to register for notifications:
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType([.Alert, .Badge, .Sound]), categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
Found the solution here on stackoverflow... Registration for notifications are sent only once on devices running versions older than iOS 9.
As answered by another user here...
"The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day."
OR
"If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on."
Reference Links:
Push Notification ON or OFF Checking in iOS
https://developer.apple.com/library/ios/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG42
I can´t make Apple Push Notifications work in development mode. The shouldSendPushNotifications method is never called on the source device when the target device is in background mode. I have uploaded my APN development certificate in the Sinch Dashboard and instant messaging works if both devices are in foreground mode. I have a valid device token which I´m using for my own Push Messages. Here is my code:
sinCli = Sinch.clientWithApplicationKey("XXXX", applicationSecret: "XXXX", environmentHost: "sandbox.sinch.com", userId: sinchUserId)
sinCli.delegate = self
sinCli.setSupportMessaging(true)
if let deviceToken = defaults.dataForKey(Globals.KEY_APN_DEVICE_TOKEN)
{
sinCli.setSupportPushNotifications(true)
sinCli.registerPushNotificationDeviceToken(deviceToken, type: SINPushTypeRemote, apsEnvironment: SINAPSEnvironment.Development)
sinCli.setPushNotificationDisplayName("MyApp")
}
sinCli.start()
sinCli.startListeningOnActiveConnection()
sinCli.messageClient().delegate = self
did I forget something?
I think I need to see your swift wrapper, but it almost looks like you are setting up the client for push (not managed), and then registring the token for managed push.
When using managed push (when you upload to cert to us) shouldSendPush is never called, because Sinch takes care of the pushing, you should just get a push. What you do need is to have a push delegate https://www.sinch.com/tutorials/ios-managed-push/
We want to make a native application using Apple push notification. We want to make a native application using Apple push notification. The problem is we want to custom the system notification when users hover on it. We notice that Skype can show the Reply button when you hover on its notification .
Does anyone know how to create a notification like Skype does?
We'd also like to be able to make a couple of other modifications as well:
Show a different notification on hover.
Show a different notification on hover, preferably with a custom view, possibly including an image or webview?
Thanks.
Update:
I found that Skype don't use APNS to push new message (when Skype doesn't run, you won't see the notification when a new message arrive). The notification on the screen is a local notification. So, in my case which using remote notification, I ignore the alert key of remote notification payload and when the app receives a remote notification, it will remove this notification from Notification Center and push a new local notification. Here is the code:
func application(application: NSApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println(userInfo)
// remove the remote one
let deliveredNotifications = NSUserNotificationCenter.defaultUserNotificationCenter().deliveredNotifications
if let lastRemoteNotif = deliveredNotifications.last as? NSUserNotification {
NSUserNotificationCenter.defaultUserNotificationCenter().removeDeliveredNotification(lastRemoteNotif)
}
// push another local notification
let localNotif = NSUserNotification()
localNotif.title = ""
localNotif.deliveryDate = NSDate()
localNotif.title = "CeillingNinja"
localNotif.subtitle = "This is local notification"
localNotif.informativeText = "Some text"
localNotif.contentImage = NSImage(named: "Status")
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(localNotif)
}
But when the app isn't running, user will see an empty notification in Notification Center. I still stuck at that point!
I've found this post to be really helpful in getting set up, but I have yet to see the push notification come through on the iPhone on which the pass is installed.
Passkit-push-notification-not-working-with-urban-airship
I set up my app on urban airship's site pushing to Apple's development servers. I installed a pass on my phone and run the following commands which I found in the above post:
airship = urbanairship.Airship(_UrbanAirshipPassbookKey, _UrbanAirshipPassbookMasterSecret)
airship.push({'aps': {'alert': 'Go.'}}, device_tokens=tokens)
I then see confirmation of this push in the iPhone console window in Xcode.
Received push for topic pass.xxx.xxx: {
...
aps = {
banner = "Hello";
};
and the iPhone then sends its update tag back along with its pass type ID and Device Library ID to the web service. At this point the web service is supposed to send back a list of changed passes. However, I instead see the following error message:
<Warning>: Web service error for pass.mypasstype.id (http://192.168.30.209:8000): Response to 'What changed?' request included 1 serial numbers but the lastUpdated tag (2013-02-11T17:25:25) remained the same.
Does anyone know why this is happening? Do I need to actually modify a field in the pass to get the push notification to appear on the device?
The short answer to your question is yes, you do need to modify a field in the pass to get a push notification to show. This is because, unlike with app pushes, a Passbook push payload does not determine the content of the notification.
The purpose of a Passbook push message is to alert the device that the web service has a new pass with updated content. The alert text is determined solely by the new pass contents. Any content in the push payload is ignored. Apple advise a push notification with an empty JSON dictionary.
Once a push is sent, it triggers the following chain:
Device receives push and queries web service with the passTypeIdentifier and lastUpadted tag
Web service provides a list of serials for all passes with the passTypeIdentifier that have changed since the lastUpdated tag
Device receives serial(s) and requests the web service to send the new .pkpass bundle for each new pass
Web service send the new .pkpass bundle
Device receives the .pkpass bundle and checks it against the old pass for changes
If the following criteria are met, the device will display the notification provided in the changeMessage key:
The value has changed
The changeMessage contains the %# string
Id the %# string is not present, the pass will show a notification Pass Changed. If no changeMessage key is present for the changed value, no message will show.