Skip to content
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

Merged
merged 6 commits into from Nov 15, 2018

Conversation

janvennemann
Copy link
Contributor

@janvennemann janvennemann commented Nov 14, 2018

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

@build
Copy link
Contributor

build commented Nov 14, 2018

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

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
@ssjsamir ssjsamir self-requested a review November 15, 2018 13:17
Copy link
Contributor

@ssjsamir ssjsamir left a 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

- 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+.
Copy link
Contributor

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" }

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+.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@lokeshchdhry
Copy link
Contributor

Doc changes look good 👍

@lokeshchdhry
Copy link
Contributor

Build fails at lint. I think we cant have ios in since like { ios: "7.5.0" } but just 7.5.0

Copy link
Contributor

@garymathews garymathews left a 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.

@lokeshchdhry lokeshchdhry merged commit e553850 into tidev:master Nov 15, 2018
vijaysingh-axway pushed a commit to vijaysingh-axway/titanium_mobile that referenced this pull request Nov 22, 2018
…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
build pushed a commit to hansemannn/titanium_mobile that referenced this pull request Dec 3, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants