How to perform deeplink from widget to parent app in Objective C - objective-c

My application is a UIKit app (Swift + Objective-C), not a SwiftUI app.
After implementing this new WidgetKit how can I perform deeplink from widget to my app?
Which method in AppDelegate I will get the callback?
Check the code below:
var body: some View {
VStack {
Text(entry.date, style: .time)
.widgetURL(widgetsEntryView.deeplinkURL)
}
}
If I create the project in Swift then I am getting the callback on:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
}
Tried Link also. Can someone help me to solve this.

Which method in AppDelegate I will get the callback?
You can use application:openURL:options:
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;

Related

Change navigation root view programmatically objective c

I want to change the navigation's root view controller programmatically using objective c. I am using a storyboard. I tried to change it in-app delegate but didn't work, there's something new introduced called scene delegate where I believe I can change the root from there, but I found no resources for that matter. Can anyone help?
Use below code:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = MyRootViewController()
self.window = window
window.makeKeyAndVisible()
}
}
Reference: https://www.andrewcbancroft.com/blog/ios-development/ui-work/accessing-root-view-controller-ios13-scenedelegate/
And: How set rootViewController in Scene Delegate iOS 13

unable to launch application using deeplink url in detox for the IOS application

Unable to launch application using deeplink for the ios app in detox
Initially the landing page in non react-native, after clicking on the link will be entering into the react-native page.
Tried with the
await device.relaunchApp({url: url});
But this is not launching the deeplink url page.
Thanks in advance.
Look at this
You need update AppDelegate
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
return [RCTLinkingManager application:app openURL:url
options:options];
}
and then in tests:
await device.openURL({url: 'url://someUrl',
sourceApp: 'some.app.id'});

How to re-open the Mac Desktop App after closing it by using X?

I have created an App for Mac Desktop, it is working, but Apple rejected it because when we run the App and close it by using "X", the we can not re-open it from the dock though the App icon is still there but it doesn't open the App again and the main issue for that I am struggling is that "If we close the App then in the menu bar there is no option to open it" other App which I have seen does that.
What should I do?
Here's an answer for Swift 3:
Conform to NSWindowDelegate in your View Controller class. Then hide the window instead of closing it by overriding the following method.
self.view.window?.delegate = self
func windowShouldClose(_ sender: Any) -> Bool {
NSApplication.shared().hide(self)
return false
}
Then unhide the application when the app icon is clicked in the dock.
func applicationDidBecomeActive(_ notification: Notification) {
NSApplication.shared().unhide(self)
}
To implement simple show/hide functionality for the red (x) button, make your App Delegate class the window delegate for your main window, as well.
Then add the following code to it:
- (BOOL)windowShouldClose:(id)sender {
[[NSApplication sharedApplication] hide:self];
return NO;
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[[NSApplication sharedApplication] unhide:self];
}
my 2 cernts for swift 5/Xcode 10
note: You can call these methods also in ViewController (if useful) to prevent splitting code between NASWindow/NSView-Controllers.
in this case:
class ViewController: NSViewController, **NSWindowDelegate**
{
...
override func viewWillAppear() {
// we choose to delegate ourselves. must be done here, in viewDidLoad window is nil
let window = self.view.window
window!.delegate = self
}
...
no neeed to pass self.. : (as per other guys above.)
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApplication.shared.hide(nil)
return false // prevent closing.
}
func applicationDidBecomeActive(_ notification: Notification) {
NSApplication.shared.unhide(nil)
}

FinishedLaunching override?

In Monotouch, there is an override for FinishedLaunching... what is the equivalent in Obj-C?
In your AppDelegate object implemetation:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// ...
}
The applicationDidFinishLaunching: method of the NSApplication delegate will be called when the app has finished loading.
Many of the default project templates provided by Xcode set up an NSApplication delegate for you. For instance, if you're building a project called SpokaneApp, you'll have a class called SpokaneAppDelegate created for you. You can add code to the applicationDidFinishLaunching method of that class to do custom application logic.

UITabBarController app - how to call method between controllers?

I have what I assume is a very simple problem, but the solution has escaped me. I have a UITabBarController app. There are two views, I'll call them A and B. And of course I have an AppDelegate class that initializes the tab bar.
View B has a button called clearScore:. When it is pressed, view B needs to invoke directly or indirectly clearScore: on view A. Can someone show me the steps to make this happen? Thanks for any help!
You can use Notifications or Key-Value-Observing (KVO).
Let's assume you've got a model object in which your property score resides. Now you add a Key-Value-Observer in you viewController B to the score property of the model instance. When you press clearScore in A you set the score property to 0(or nil). The Observer will inform B that the property changed so you can easily update your view of B.
I think there is a more simple way to achieved that:
You can use something like the below code in bViewController:
for (UIViewController* testViewController in self.tabBarController.viewControllers) {
if ([testViewController respondsToSelector:#selector(clearScore)]) {
[(aViewController *)testViewController clearScore];
}
}
Or:
for (UIViewController* testViewController in self.tabBarController.viewControllers) {
if ([testViewController isKindOfClass:[aViewController class]]) {
[(aViewController *)testViewController clearScore];
}
}
Don't forget to #import "aViewController.h" in bViewController's header;
Views should talk directly only to their own controllers, and a controller shouldn't talk to views other than its own. If one of view controller B's buttons should result in a message being sent to view controller A, then the button should trigger an action in controller B that in turn sends a message to A.
However, -clearScore: sounds like a method that would be part of a model rather than part of a controller, and the fact that B has an interest is further evidence of the same. You might want to think about refactoring your code a bit.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//other codes
[self.tabBarController setDelegate:self]
//other codes
}
// UITabBarControllerDelegate method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if ([viewController respondsToSelector:#selector(reloadDataTemp)]) {
[(YourViewController *)viewController reloadData];
}
}