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

Feature/custom sounds #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,28 @@ package com.freshplanet.nativeExtensions
* @param timestamp when the local notification should appear (in sec)
* @param title (Android Only) Title of the local notification
* @param recurrenceType
* @param soundName is the sound to play with the notification. If not used, a default sound will play
*
*/
public function sendLocalNotification(message:String, timestamp:int, title:String, recurrenceType:int = RECURRENCE_NONE,
notificationId:int = DEFAULT_LOCAL_NOTIFICATION_ID, deepLinkPath:String = null, androidLargeIconResourceId:String = null):void
notificationId:int = DEFAULT_LOCAL_NOTIFICATION_ID, deepLinkPath:String = null, androidLargeIconResourceId:String = null, soundName:String = null):void
{
if (this.isPushNotificationSupported)
{
if (notificationId == DEFAULT_LOCAL_NOTIFICATION_ID)
{
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType);
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, soundName);
} else
{
if (Capabilities.manufacturer.search('Android') > -1)
{
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, notificationId, deepLinkPath, androidLargeIconResourceId);
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, soundName, notificationId, deepLinkPath, androidLargeIconResourceId);
} else // iOS doesn't support null params
{
if(deepLinkPath === null) {
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, notificationId);
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, soundName, notificationId);
} else {
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, notificationId, deepLinkPath);
extCtx.call("sendLocalNotification", message, timestamp, title, recurrenceType, soundName, notificationId, deepLinkPath);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ protected void onPostExecute(Boolean downloadSuccess)
}

// Notification sound
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Uri soundUri = null;
String soundName = _intent.getStringExtra("soundName");
if(soundName == null){
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}else{
soundUri = Uri.parse("android.resource://" + _context.getPackageName() + "/raw/" + soundName);
}

// Notification action
Intent notificationIntent = new Intent(_context, NotificationActivity.class);;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public FREObject call(FREContext arg0, FREObject[] arg1) {
long timestamp = 0;
String title = null;
int recurrenceType = RECURRENCE_NONE;
String soundName = null;
int notificationId = DEFAULT_NOTIFICATION_ID;
String largeIconResourceId = null;
try {
Expand All @@ -73,15 +74,20 @@ public FREObject call(FREContext arg0, FREObject[] arg1) {
{
recurrenceType = arg1[3].getAsInt();
}

if (arg1.length >= 5)
{
notificationId = arg1[4].getAsInt();
soundName = arg1[4].getAsString();
}

if (arg1.length >= 6)
{
notificationId = arg1[5].getAsInt();
}

if (arg1.length >= 7 && arg1[6] != null)
if (arg1.length >= 8 && arg1[7] != null)
{
largeIconResourceId = arg1[6].getAsString();
largeIconResourceId = arg1[7].getAsString();
}

} catch (IllegalStateException e) {
Expand Down Expand Up @@ -145,6 +151,12 @@ public FREObject call(FREContext arg0, FREObject[] arg1) {
{
am.set(AlarmManager.RTC_WAKEUP, timestamp, sender);
}

if (soundName != null)
{
intent.putExtra("soundName", soundName);
}

Log.d(TAG, "setting params to run at "+Long.toString(timestamp));

} else
Expand Down
Binary file modified bin/AirPushNotification.ane
Binary file not shown.
24 changes: 17 additions & 7 deletions ios/AirPushNotification/AirPushNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,28 @@ void didReceiveRemoteNotification(id self, SEL _cmd, UIApplication* application,
FREGetObjectAsUint32(argv[3], &recurrence);
}

// sound name : UILocalNotificationDefaultSoundName is default
NSString* soundName = UILocalNotificationDefaultSoundName;
if(argc >= 5)
{
const uint8_t *utf8_soundName;
if (FREGetObjectAsUTF8(argv[4], &string_length, &utf8_soundName) == FRE_OK)
{
soundName = [NSString stringWithUTF8String:(char*)utf8_soundName];
}
}

// local notif id: 0 is default
uint32_t localNotificationId = 0;
if (argc >= 5)
if (argc >= 6)
{
if (FREGetObjectAsUint32(argv[4], &localNotificationId) != FRE_OK)
if (FREGetObjectAsUint32(argv[5], &localNotificationId) != FRE_OK)
{
localNotificationId = 0;
}
}



NSNumber *localNotifIdNumber =[NSNumber numberWithInt:localNotificationId];

[AirPushNotification cancelAllLocalNotificationsWithId:localNotifIdNumber];
Expand All @@ -239,16 +249,16 @@ void didReceiveRemoteNotification(id self, SEL _cmd, UIApplication* application,
return NULL;
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];

localNotif.alertBody = message;
localNotif.alertAction = @"View Details";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.soundName = soundName;

if (argc == 6) // optional path for deep linking
if (argc == 7) // optional path for deep linking
{
uint32_t path_len;
const uint8_t *path_utf8;
if (FREGetObjectAsUTF8(argv[5], &path_len, &path_utf8) == FRE_OK) {
if (FREGetObjectAsUTF8(argv[6], &path_len, &path_utf8) == FRE_OK) {
NSString* pathString = [NSString stringWithUTF8String:(char*)path_utf8];
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:localNotifIdNumber, @"notifId", pathString, @"path", nil];
} else {
Expand Down