I am trying to set the appIconBadgeNumber along with a local notification as
[localNotif setApplicationIconBadgeNumber:count];
but the badge occurs as soon as the application enters the background where as the Notification is fired at its scheduled time.
please help i am a beginner in iPhone development.
thanks in advance.
You have to set the badge when the notification fires. In your app delegate, implement this method:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
notif.applicationIconBadgeNumber = 1;
}
Also be prepared for cases when the notification fires while your app is in the background:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opt {
// ...
UILocalNotification *notif = [opt objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
notif.applicationIconBadgeNumber = 1;
// ...
return YES;
}
Related
Till iOS12, I was using following code to handle tap event on status bar:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let statusBarRect = UIApplication.shared.statusBarFrame
guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return }
if statusBarRect.contains(touchPoint) {
//Status bar tapped
}
}
}
But, now it's not working for iOS 13. Please help me on the same.
A view in your app that's behind the status bar cannot be touched. You should not be trying, in your app, to detect a tap "on the status bar"; it isn't even part of your app (it's a window imposed by the runtime). It can't be done.
I am using Xamarin.Essentials Phone Dialer in my xamarin forms app to make calls. In android when we click call it will directly open dialer. In ios when we click call it will firstly show a alert box that will ask Call or cancel. Is it possible to open the dialer in ios without showing the popup? If it is not possible can we get the alert box cancel or call click event?
Unfortunately, this is not possible in iOS.
From Apple's documentation:
openURL
When a third party application invokes openURL: on a tel://,
facetime://, or facetime-audio:// URL, iOS displays a prompt and
requires user confirmation before dialing.
For security reasons, iOS requires users to confirm they want to perform the call before dialing in.
Is it possible to open the dialer in ios without showing the popup?
No, it is by design.
can we get the alert box cancel or call click event
You have to detect the state of phone call by yourself in the iOS project, you can write below codes in the AppDelegate:
CXCallObserver callObserver = new CXCallObserver();
callObserver.SetDelegate(new myDelegate(), DispatchQueue.MainQueue);
And in the delegate, you can check the call state:
public class myDelegate : ICXCallObserverDelegate
{
public IntPtr Handle => throw new NotImplementedException();
public void CallChanged(CXCallObserver callObserver, CXCall call)
{
if (call.Outgoing==true && call.HasConnected ==false)
{
Console.WriteLine("Dialing");
//use Messaging Center to send the state to Xamarin.forms Project.
}
if (call.Outgoing ==false && call.HasConnected == false)
{
Console.WriteLine("disconnect");
//use Messaging Center to send the state to Xamarin.forms Project.
}
//you can use other state to check the state...
//call.OnHold; call.HasEnded;
}
public void Dispose()
{
}
}
My app receives toast from PHP using WNS server. Now I want to perform some actions when clicking on toast as listed below.
When the app is not active - the user should redirect to a page on the app "ShowPage".
When the app is active - the toast should show two buttons "Show" and "Cancel". When clicking on Show button app should redirect to "ShowPage"
My current toast from PHP is
$toastMessage= '<?xml version="1.0" encoding="utf-8"?>'.
'<toast launch="">'.
'<visual baseUri="">'.
'<binding template="ToastGeneric">'.
'<text>'.$subtitle.'</text>'.
'</binding>'.
'</visual>'.
'<actions />'.
'</toast>';
And I'm calling below function on App.xaml.cs
private async void RegisterEngagementNotification()
{
StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault();
await engagementManager.RegisterNotificationChannelAsync();
}
Please see the documentation for sending a local toast and handling activation. Everything applies there (other than you're sending the toast from your server, but otherwise adding buttons and handling activation remains the same).
I saw that you're using StoreServicesEngagementManager APIs, then I know you're sending toast notification from windows developer dashboard. So, if you want to your toast contains two buttons, you would need to add actions like the following:
Then, in your "App.xaml.cs" file, you would need to add some code to handle this option in OnActivated.
protected override void OnActivated(IActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
}
base.OnActivated(args);
var toastActivationArgs = args as ToastNotificationActivatedEventArgs;
if (toastActivationArgs.Argument =="ShowPage")
{
rootFrame.Navigate(typeof(ShowPage));
}
}
I have to detect screen touches in VR mode, as that's what the button on a Cardboard produces. (I have other code to detect controller buttons.)
This code:
// mobile and Cardboard controls
AFRAME.scenes[0].addEventListener('touchstart', function(evt) {
// console.log('scene touchstart:', evt);
if (evt.target.classList.contains('a-enter-vr-button')) {
return;
}
if (!state.isFlying) {
AFRAME.scenes[0].emit('launch', evt);
} else {
AFRAME.scenes[0].emit('hover', evt);
}
});
fires when the screen is tapped, in Android Firefox in normal and VR mode (but VR mode is polyfilled). In Android Chrome, it fires in normal mode, but not VR mode (which appears to be native).
The same behavior occurs when I listen for mousedown, or add the listener to window, for either touchstart or mousedown.
So, what event on what element should I listen for, in native VR mode?
Add the event listener to the window or to the canvas (AFRAME.scenes[0].canvas).
window.addEventListener('click', function () { // ... } or
window.addEventListener('touchstart', ...)
VR Mode in Chrome had a virtual controller. My eventual solution was to write a component that detected both screen taps and controller buttons:
https://www.npmjs.com/package/aframe-button-controls
I would like to make popover view visible whenever user switches from landscape view to portrait view in UIsplitView of iPad. Although user can make it visible by clicking on bar button but I want this to be automated for portrait mode.
Inside " -(BOOL) shouldAutorotateToInterfaceOrientation" method, check for the device orientation.If it is portrait, then Present the popover as you do for making it visible when user clicks bar button.
All the best.
UISplitViewController sends messages to his delegate (UISplitViewControllerDelegate). You can implement this delegate methods to show the popover. You can do something like this in your "detail controller" code:
#pragma mark -
#pragma mark UISplitViewControllerDelegate implementation
- (void)splitViewController:(UISplitViewController*)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController:(UIPopoverController*)pc
{
[barButtonItem setTitle:#"Your 'popover button' title"];
self.navigationItem.leftBarButtonItem = barButtonItem;
}
- (void)splitViewController:(UISplitViewController*)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
self.navigationItem.leftBarButtonItem = nil;
}
The accepted answer (using shouldAutorotateToInterfaceOrientation) doesn't work for me. It either has rotation artifacts (in the 4.2 and 5.0 iPad simulators) or only shows at startup and never again in subsequent rotations (the 4.3 simulator). What I did instead was to create a little helper function:
- (void)showPopoverInPortrait {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
[self.masterPopoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
and call this within - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation and - (void)viewDidLoad to also handle on startup.