I am developing chat application in os x with XMPP framework, where there is main chat viewcontroller with chat view but when user clicks logout button i navigate user to login viewcontroller by calling offline method,xmpp disconnect method and self window close. After this during re-login xmpp connection is not happening.
code used :
-(void)logout
{
[self goOffline];
[self xmppStreamDidDisconnect:xmppStream withError:nil];
ViewController *bcktologin =[self.storyboard instantiateControllerWithIdentifier:#"ViewController"];
[self presentViewControllerAsModalWindow:bcktologin];
[self dismissViewController:self];
[self.view.window close];
}
so after this:
My chat controller keeps running behind, menu created in it is no removed.
No connection to XMPP after re-login
Please guide.
Related
I am developing a safari web extension. I need send data from Web Extension’s background page to native app. Native app gets this message and signs it with USB key to generate a signature value. Then Native app sends the signature value back to background page.
Messaging a Web Extension’s Native App
First, I create a port in background.js
let port = browser.runtime.connectNative("application.id");
Add a listener to that port to receive message from Native App,as follow:
port.onMessage.addListener(function(message) {
console.log("Received native port message:");
console.log(message);
});
In my native app, I can send message to background page with following codes:
SFSafariApplication.dispatchMessage(withName: "Hello from App",
toExtensionWithIdentifier: extensionBundleIdentifier,
userInfo: ["AdditionalInformation": "Goes Here"],
completionHandler: { (error) -> Void in
os_log(.default, "Dispatching message to the extension finished")
})
But how can I send message from background page to Native App?
In “Messaging a Web Extension’s Native App” demo, messages are send by following code:
port.postMessage("Hello from JavaScript Port");
But there are no codes to show how to receive this message in native app.
In native app, How can I receive messages sent by “postMessage” from background page? If you can provide a demo with object-C, I will be very grateful. Thanks!
Found the following answer to your question in the WWDC'20 session Meet Safari Web Extensions
App ⭤ extension:
Shared NSUserDefaults from an app group, or NSXPCConnection
See also WWDC NOTES
I'm working on a Xamarin.Forms app using the Prism library. The app has a phone component to it with integration to CallKit and a SIP library. When the device is locked, a call can be received, which results in the native phone UI for iOS. User can answer the call and hangup. Within the app, there is a Xamarin.Forms page to handle calls. There are events from the iOS service that deals with the calls to interact with the "shared project". The issue that I am running in to is that when the user unlocks the device and returns to the app, the UI is non-responsive.
Scenario:
User starts app and logs in.
User locks device
Incoming call received
User answers call
Behind the scenes (i.e. native phone UI), the call service communicates with the "shared project" to display a Call Screen in the app. Since the phone is locked, the user will not see this now.
User hangs up.
When user hangs up, the call service communicates with the "shared project" that the call has been terminated and to return to the previous screen.
User then unlocks the screen
App is on same screen as when user locked device, but UI is not responsive.
To navigate to the call page, I am doing:
await NavigationService.NavigateAsync(targetPage, null, useModalNavigation: null, animated: animated);
and to return to previous page:
await NavigationService.GoBackAsync(animated: false, parameters: parameters);
NavigationService is of type INavigationService from Prism.
The essential question is: what would make the navigation appear to work, but result in a non-responsive UI? I've found in the past that I need to do the navigation on the main thread. Is there anything else I need to look for?
What I understood that you are looking for a method just like the OnAppearing method of forms page.
You need to implement interface INavigatedAware to your ViewModel. By doing this, 2 methods will be added to your ViewModel "NavigatedTo" and "NavigatedFrom". You need to put your logic into the "NavigatedTo" method. This method will be triggered whenever that particular page will appear on the screen.
I'm building a Windows 8.1 App using Ionic 3. In the app, the user would have to type in a lot of stuff. I want to avoid accidental closure of the app by clicking on 'X' button at the top right corner or by Alt+F4. When the user tries to close the app, is there a way to prevent the default behaviour of closing the app and instead ask a confirmation?
You must override the onbackbutton event to do this.
document.addEventListener('backbutton', function (evt) {
/* BackButton pressed: do nothing */
return;
}, false);
Do NOT use the method shown on that page to exit the app:
throw new Error('Exit'); // This will suspend the app BUT the store will reject it
If you do this to exit your app, it will be rejected by the Microsoft store. To exit the app, remove the event listener and let the backbutton event suspend the app normally.
There's no special event to indicate that the user has closed an app.
App Lifecycle docs for Windows Store Apps.
https://learn.microsoft.com/en-us/previous-versions/windows/apps/hh464925(v=win.10)?redirectedfrom=MSDN#app-close
When the user closes the app or moves the app to background, it enters into a Suspended State. Windows recommends saving user state when the app enters such a state. You can save data in that state thereby achieving the overall goal.
I try to register only alert type notification at application start in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
by calling
UIUserNotificationType types = UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
In
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
I permanently get all types in notificationSettings
<UIUserNotificationSettings: 0x16dd6160; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>
And
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings]
gives me the same all types despite my initial choice of the only alert type.
So I can't setup restricted dynamical permissions on start.
There is no any information about similar problems in the internet.
It seems that it is impossible to setup UserNotificationType from application in iOS8 (at least). One needs to use general Notification Center to set any combination of sound, badge and alert. Only the first attempt to register which occurs with Push notification permissions alert sets UserNotificationType needed.
Another way is to send UserNotificationType on subscription to your push server which should make payload depending of this type.
You must register notifications in (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UPDATE:
According to the Apple documentation:
The first time you call the registerUserNotificationSettings: method,
iOS presents a dialog that asks the user for permission to present the
types of notifications the app registered. After the user replies, iOS
asynchronously calls back to the UIApplicationDelegate object with the
application:didRegisterUserNotificationSettings: method, passing a
UIUserNotificationType object that specifies the types of
notifications the user allows.
Users can change their notification settings at any time using the
Settings app. Your app is added to the Settings app as soon as you
call registerUserNotificationSettings:. Users can enable or disable
notifications, as well as modify where and how notifications are
presented. Because the user can change their initial setting at any
time, call currentUserNotificationSettings before you do any work
preparing a notification for presentation
So if user has already accepted Notification settings, application can't change them. currentUserNotificationSettings always show current user settings, not application settings.
My product works as following:
My application opens notification
My application exits
Now, when the user clicks the notification, my application is opened again. I DONT WANT it. I want that if user clicks the notification - it will just disappear
I found there is a callback for that (and it works)
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
[center removeDeliveredNotification: notification];
}
but it works only when my application is running.
Is it possible to implement the behavior I want at all?
No it isn't possible to avoid having your application launched when a user touches your notification.
The application will always be launched in response to touching a notification and the UIApplicationDelegate method application:willFinishLaunchingWithOptions: will always be called when the application is not running.
Your app doesn't have to action on the notification, but it will be launched.