I can't seem to find any method to set notification arrive in big view (multi-line message in notification). Is anyone know how to set this thing up?
here is the example from native android = Native Android Notification Big View
This should help you setup a local notification, if that's what you are referring to:
http://docs.coronalabs.com/guide/events/appNotification/index.html#localnot
Example code:
local futureTime = 9 * 60 --9 minute alarm "snooze"
--OR:
local futureTime = os.date( "!*t", os.time() + (9 * 60) )
local options = {
alert = "Wake up!",
badge = native.getProperty( "applicationIconBadgeNumber" ) + 1,
sound = "alarm.caf",
custom = { msg = "Alarm" }
}
local notificationID = system.scheduleNotification( futureTime, options )
Related
I want to when user get notification from fcm (Firebase Cloud Messaging) or scheduler local notification like alarm notification like image below :
Here my code :
func onTest() {
let content = UNMutableNotificationContent()
content.title = "Weekly Staff Meeting"
content.body = "Every Tuesday at 2pm"
// Configure the recurring date.
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.hour = 16 // 14:00 hours
dateComponents.minute = 11
// Create the trigger as a repeating event.
let trigger = UNCalendarNotificationTrigger(
dateMatching: dateComponents, repeats: true)
// Create the request
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
}
}
}
My code right now just like the usual notification which disappears in 5 seconds I want to make it like an Alarm notification or Whatsapp Calling Notification. Please Help Thanks.
Due to Apple's limitation, app dev can only play notification tone up to 30 seconds. It will play default notification tone if your tone is longer than 30 seconds.
If your notification tone is gone after 5 seconds, try to set your notification presentation options to list, badge and sound.
Once there's no banner for notification, your 30seconds tone will play till the end.
Unfortunately there's no legal way or any workaround to have notification ring continuously such as alarm clock. Hope I was wrong though.
https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions
What I think, max you can do is to present a local notification. But yes that would not be exactly like an Apple Alarm notification. In Reality, you don't have permission for this. You can only present the local notifications.
Since UILocalNotification was deprecated in iOS10, I'm having trouble understanding how to update the following code to the UNNotificationRequest framework. Im basically letting a user schedule a daily notification at a time of their choosing. For example, if they want to get a notification everyday at 11:00AM. The below code works for iOS versions below iOS10 but since UILocalNotification is deprecated, it no longer works. Any help is greatly appreciated.
let notification = UILocalNotification()
notification.fireDate = fixedNotificationDate(datePicker.date)
notification.alertBody = "Your daily alert is ready for you!"
notification.timeZone = TimeZone.current
notification.repeatInterval = NSCalendar.Unit.day
notification.applicationIconBadgeNumber = 1
UIApplication.shared.scheduleLocalNotification(notification)
You can use UNCalendarNotificationTrigger for creating a notification that fires repeatedly using UNUserNotificationCenter. You can do something like this. The trick is to only have the time component in the Trigger date.
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Attention!"
content.body = "Your daily alert is ready for you!"
content.sound = UNNotificationSound.default
let identifier = "com.yourdomain.notificationIdentifier"
var triggerDate = DateComponents()
triggerDate.hour = 18
triggerDate.minute = 30
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: true)
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
if let error = error {
// Something went wrong
print("Error : \(error.localizedDescription)")
} else {
// Something went right
print("Success")
}
})
You can't schedule a notification that repeats daily. That notification would happen only once, and then you would have to schedule it again, which means that you would have to open the app again.
There is BGTask API introduces in iOS 13, that can be used to perform some background tasks, but not this one, you can not schedule the task for specific time.This API last only works when app is in the background, not when it is killed. You can only set some time interval that the system will use as a guiding point to determine when to perform you app's code. But in my experience it is pretty unreliable.
The only way to achieve this is to implement remote push notifications. Push notifications also work even when the app is killed.
when I'm receiving push notification on iOS 13, and device is locked. I' getting pushnotifcation, but it gets cleared immediately without any user interaction.
I'm using .net and following is payload code which I'm using
{to = notification.DeviceToken,
priority = "high",
content_available = true,
notification = new
{
body = notification.Message, //This will be a subtitle..
title = notification.Name, //This will be a title..
},
data = new
{
notificationId = notification.NotificationId,
userId = notification.UserId,
encryptedNotification = Crypto.Encrypt("id", notification.NotificationId.ToString())
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
**tRequest.Headers.Add("apns-push-type", "alert");**
**tRequest.Headers.Add("apns-priority", "5");**
}```
Please guide me what wrong in code.
have referred following azure code to implement, but not able to find the cause.
https://learn.microsoft.com/en-us/azure/notification-hubs/push-notification-updates-ios-13
This can happen if you have a code that decreases the app icon's notification badge number. If you do that, make sure you do it only if the application is active. If it is inactive and you decrease the badge number, it might cause the notification to appear and immediately disappear.
I have implemented the VoIP Push. everything works fine but when app recieves push, mobile starts ringing and just after 1-2 sec(the length of my .wav file) it stops.
I want: Sound should ring until user accept/reject the call.
My solutions
I should place the lengthy sound so it keeps on
ringing?
Or i should send the Voip Push Again and again untill user cancels/attend call?
After recieving push I should localy fire the push again and again.
I hope once you receive pushkit payload, then you are scheduling local notification and local notification is having sound file.
Sound file plays on 2 things, length of sound file ( 5 / 10 / 15 Seconds ) or max upto 30 seconds.
So if your sound file is less then 30 seconds, then edit your sound file and make repetitive till 30 seconds.
If you want to play sound file for more than 30 seconds then either you have reschedule local notification with sound file at each 30 seconds till user accept call or resend push kit payload from back end.
After all this things still your sound file stops in 1/2 seconds, then do check may be your app is crashing in background or terminated state.
Code
#available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
// Process the received push
var arrTemp = [NSObject : AnyObject]()
arrTemp = payload.dictionaryPayload
let dict : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>
if "IfUserHasLoggedInWithApp" // Check this flag then only proceed
{
if UIApplication.sharedApplication().applicationState == UIApplicationState.Background || UIApplication.sharedApplication().applicationState == UIApplicationState.Inactive
{
if "CheckForIncomingCall" // Check this flag to know incoming call or something else
{
var strTitle : String = dict["alertTitle"] as? String ?? ""
let strBody : String = dict["alertBody"] as? String ?? ""
strTitle = strTitle + "\n" + strBody
let notificationIncomingCall = UILocalNotification()
notificationIncomingCall.fireDate = NSDate(timeIntervalSinceNow: 1)
notificationIncomingCall.alertBody = strTitle
notificationIncomingCall.alertAction = "Open"
notificationIncomingCall.soundName = "SoundFile.mp3"
notificationIncomingCall.category = dict["category"] as? String ?? ""
notificationIncomingCall.userInfo = "As per payload you receive"
UIApplication.sharedApplication().scheduleLocalNotification(notificationIncomingCall)
}
else
{
// something else
}
}
}
}
Debug pushkit notification in terminated state
Put debug pointer on delegate methods
Go to edit scheme
Select run option then Launch -> Wait for executable to be launched
Send push kit payload from back end
Once you get payload on device
it will automatically invoke and debug pointer will invoke at delegate methods.
You can refer some details here.
https://github.com/hasyapanchasara/PushKit_SilentPushNotification
I have a game that I'm adding a timer when the player loses, of 3 hours for now. When the time passes out, the player can get free 15 coins of my game.
For now, I'm using NSTimer. The problem is that whenever i put the game in background mode, the timer stops as I read in the documentation. So the timing would run only for game playtime and not always.
How can I achieve this? I will even send a Notification to the user when that timer ended so the user can get into my game and grab the coins for free.
Here's what i have so far:
var coinCountdown = 10800 // 3hr = 10800
var coinCurrentTimer = NSTimer.init()
var coinCountdownLabel = SKLabelNode()
Then in the init of my SKScene I do:
self.coinCurrentTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(GameScene.updateCoinCountdown), userInfo: nil, repeats: true)
And this is the updateCoinCountdown method:
func updateCoinCountdown() {
if(self.coinCountdown > 0){
var hour = String(self.coinCountdown / 3600)
var minutes = String((self.coinCountdown % 3600) / 60)
var seconds = String((self.coinCountdown % 3600) % 60)
if Int(hour) < 10 {
hour = "0" + hour
}
if Int(minutes) < 10 {
minutes = "0" + minutes
}
if Int(seconds) < 10 {
seconds = "0" + seconds
}
self.coinCountdownLabel.text = hour + ":" + minutes + ":" + seconds
self.coinCountdown = self.coinCountdown - 1
let defaults = NSUserDefaults.standardUserDefaults()
if defaults.valueForKey("coinCountdown") != nil {
defaults.setValue(self.coinCountdown, forKey: "coinCountdown")
}
}else{
print("Done! Send notification and show get coin button")
}
}
Any hint would be very appreciated.
I haven't actually done something like this yet, but I have an idea how it could be done.
When the 'timer' is supposed to start you could schedule a local silent notification that would alert the app that the time has passed or an event has been triggered.
When the app receives this scheduled notification it could run some basic checks to see if anything has happened since the notification was scheduled that may cancel it out, if not then it could trigger an immediate local notification to alert the user of the event.
See the documentation for Local and remote notifications it even has a reference to an event in which the "TIMER_EXPIRED" which is similar to my suggestion above.
EDIT: Looking over the documentation it doesn't look like you can schedule a silent notification, but in theory this could still work for your case.