New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ios): trigger event when receiving local notification in foreground #10468
Conversation
Generated by 🚫 dangerJS |
ebc9ddb
to
f636527
Compare
properly trigger event for local notification when on iOS 10. also updates the docs to reflect recent changes to the event object. resolves TIMOB-26559
f636527
to
6460b21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FR Passed: Trigger event no longer crashes application when receiving notifications in the foreground.
Test cases tested:
https://jira.appcelerator.org/browse/AC-5993
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND, Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
],
});
var tempdate = new Date(new Date().getTime() + 5000);
var curNotif = {
alertBody : "Me",
alertTitle : 'It is me',
badge: 99,
userinfo: {id: '123'},
date: tempdate
};
Ti.App.iOS.scheduleLocalNotification(curNotif);
https://jira.appcelerator.org/browse/AC-6013
// START IF - Check if the device is running iOS 8 or later
if (parseInt(Ti.Platform.version,10) >= 8) {
// START FUNCTION - registerForPush
function registerForPush() {
Ti.Network.registerForPushNotifications({
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
};
// END FUNCTION - registerForPush
// ADD Eventlistener to Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', registerForPush);
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
}else{ // ELSE - Check if the device is running iOS 8 or later
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
};
// END IF - Check if the device is running iOS 8 or later
// Start Function - deviceTokenSuccess
function deviceTokenSuccess(e) {
Ti.API.info("Register with deviceToken: " + e.deviceToken);
};
// End Function - deviceTokenSuccess
// Start Function - deviceTokenError
function deviceTokenError(e) {
Ti.API.info("Failed to Find Token" + e.error);
};
// End Function - deviceTokenError
// START FUNCTION - receivePush for iOS
function receivePush(e) {
Ti.API.info("Received Push:" + JSON.stringify(e));
};
// END FUNCTION - receivePush for iOS
Ti.App.iOS.addEventListener('notification', function(e) {
Ti.API.info("Received Local push in foreground:" + JSON.stringify(e));
});
Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
Ti.API.info("Received Local push in background:" + JSON.stringify(e));
});
// The following code snippet schedules an alert to be sent within three seconds
var notification = Ti.App.iOS.scheduleLocalNotification({
category: "TEST",
alertAction: 'Read now',
alertBody: 'Custom message',
date: new Date(new Date().getTime() + 30000),
//repeat: "daily",
//The following URL is passed to the application
userInfo: {
"task": "test2"
}
})
https://jira.appcelerator.org/browse/AC-6015
// START FUNCTION - registerForPush
function registerForPush() {
Ti.Network.registerForPushNotifications({
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
};
// END FUNCTION - registerForPush
// ADD Eventlistener to Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', registerForPush);
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
// Start Function - deviceTokenSuccess
function deviceTokenSuccess(e) {
Ti.API.info("Register with deviceToken: " + e.deviceToken);
};
// End Function - deviceTokenSuccess
// Start Function - deviceTokenError
function deviceTokenError(e) {
Ti.API.info("Failed to Find Token" + e.error);
};
// End Function - deviceTokenError
// START FUNCTION - receivePush for iOS
function receivePush(e) {
Ti.API.info("Received Push:" + JSON.stringify(e));
};
// END FUNCTION - receivePush for iOS
Ti.App.iOS.addEventListener('notification', function(e) {
Ti.API.info("Received Local push in foreground:" + JSON.stringify(e));
});
Ti.App.iOS.addEventListener('localnotificationaction', function(e) {
Ti.API.info("Received Local push in background:" + JSON.stringify(e));
});
// set scheduled notification
var notification = Ti.App.iOS.scheduleLocalNotification({
// Create an ID for the notification
userInfo: {"type": "localnotification", "id": 1,},
alertBody: "message",
badge: 1,
date: new Date(new Date().getTime() + 10000),
repeat: "monthly", // ANOTHER BUG << https://jira.appcelerator.org/browse/AC-6013
});
Test environment
APPC Studio: 5.1.0.201808080937
iPhone 6 Sim (iOS 10.3)
APPC CLI: 7.0.6
Operating System Name: Mac OS Mojave
Operating System Version: 10.14.1
Node.js Version: 8.9.1
Xcode 10.0
Awaiting CR
apidoc/Titanium/App/iOS/iOS.yml
Outdated
- name: threadIdentifier | ||
summary: | | ||
The unique identifier for the thread or conversation related to this notification request. | ||
It will be used to visually group notifications together. Available in Titanium SDK 7.4.0+ and iOS 10+. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a new property, shouldn't this be Available in Titanium SDK 7.5.0+
Also, shouldn't we be doing:
since: { ios: "7.5.0" }
apidoc/Titanium/App/iOS/iOS.yml
Outdated
type: String | ||
|
||
- name: category | ||
summary: The identifier of the app-defined [category object](Titanium.App.iOS.UserNotificationCategory). Available in Titanium SDK 7.4.0+ and iOS 10+. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Doc changes look good 👍 |
Build fails at lint. I think we cant have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: PASS
Jenkins failing due to unrelated test.
…nd (tidev#10468) * fix(ios): trigger event when receiving local notification in foreground properly trigger event for local notification when on iOS 10. also updates the docs to reflect recent changes to the event object. resolves TIMOB-26559 * fix(ios): set threadIdentifier if running iOS 10 or above * docs(api): update since version to 7.5.0 * docs(api): fix platform identifier
…nd (tidev#10468) * fix(ios): trigger event when receiving local notification in foreground properly trigger event for local notification when on iOS 10. also updates the docs to reflect recent changes to the event object. resolves TIMOB-26559 * fix(ios): set threadIdentifier if running iOS 10 or above * docs(api): update since version to 7.5.0 * docs(api): fix platform identifier
properly trigger event for local notification when on iOS 10. also updates the docs and the event object itself so both are in sync again.
resolves TIMOB-26559