A method is depreciated in framework but cannot apply suggested change - objective-c

I'm using a framework that is written in-house and when I try to reduce the amount of warnings I have there is one that comes up constantly, which is 'Implementing depreciated method'. the method in question is openURL
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
When I go to the Framework code I can see where it is depreciated and a suggested change
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;
The suggestion is to use openURL:options. Looking at the documentation for openURL it says I should use like the following
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:#{} completionHandler:nil];
However, this doesn't work, I cannot separate the parameter openURL from the method as it states above when my method looks like this
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
..
}
How do I implement the new suggested change into my existing method call as above?

The method that you need to implement is application:openURL:options: instead of deprecated one application:openURL:sourceApplication:annotation:. So replace your method with below one
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
//Your code ..
}
Note :- The instance method openURL:options:completionHandler: that you are trying to use is used to open the resource at the specified URL asynchronously.

Related

Conflict between React Native FBSDK, Deep Linking and Redux

I'm currently going through an issue with the React Native FBSDK, Deep Linking and Redux.
I'm supposed to add this code to my existing project because they both use the same method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
Exisiting code
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
I have found multiple potential fixes as mentioned in this thread:
https://github.com/reduxjs/redux/issues/2359
but none of they work, they all still send me the following error message:
cannot read property 'apply' of undefined
It seems to be linked to redux and the way we set up the store but I'm not sure how to fix this.
Has anybody gone through a similar problem?
I would greatly appreciate any help on that.

Push notification not receiving when app is in background using parse

Push notification not receiving when app is in background .If application is in foreground it is working fine,if app in background after receiving notification need to start some process.
Here my code is :
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
if (application.applicationState == UIApplicationStateInactive)
{
NSLog(#" background userInfo =%#",userInfo);
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"%#",userInfo);
}
My Environment : iOS8,Xcode 6.3,Mac10.10.
For iOS8 you need to use the second of the following delegate methods:
// < iOS7
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
// >= iOS7
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

Duplicate Declaration of Method 'ApplicationDidBecomeActive'

// Created by Robert Van Gilder on 30/05/2014.
// Copyright (c) 2014 Robert Van Gilder. All rights reserved.
//
#import "AppDelegate.h"
#import <FacebookSDK/FacebookSDK.h>
#import <Parse/Parse.h>
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PFFacebookUtils initializeFacebook];
{[Parse setApplicationId:#"ycWShHVTsY7Xawt0dupTN1YMWFeyMLlhG7K9R0rZ"
clientKey:#"8AmzExUoqvmppa5k3eaS37RBNB6c1StmlysvvjBr"];}
{[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController* initialViewController = [storyboard instantiateViewControllerWithIdentifier:#"MainViewController"];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
I get the error in the title at
- (void)applicationDidBecomeActive:(UIApplication *)application. I don't get why this happens. I'm using the Parse SDK along with the Facebook login, and I'm following Parse's instructions, however when I add this code part below, the compiler doesn't understand it properly and creates various errors.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
You have a duplicate declaration of -applicationDidBecomeActive. The first one is indented incorrectly, just below -application:openURL:sourceApplication:annotation:. The second is between -applicationWillEnterForeground: and -applicationWillTerminate:.

NSLog from appDelegate

Inside AppDelegate.m I am trying to grab the stuff from a string I am getting from an incoming URL. I'm not sure why NSLog is not printing anything out...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions openURL:(NSURL *)url
{
// incoming URL...
// i.e. palsvid://blabla.com/foo.php?request=laa&id=1004
NSString *q = [url query];
NSLog(#"%#",q); // Does not log anything! Even with a hard coded string!
NSArray *pairs = [q componentsSeparatedByString:#"&"];
// ...
Am I doing something wrong? I update plist to accept the url, now I want to parse it.
Eventually I will take this data and use it in my ViewController. NSLog works in the ViewController methods...
Thanks
You have the wrong method signature so your method is never called. There is no openURL: parameter. You want:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// your code here
}
That is called when you app is started from scratch.
To handle your app being called from another app or being sent a URL, you need to implement the following:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// process URL here
}
Please read the docs for UIApplicationDelegate as well as the related app life cycle docs.

how to load a tab from appdelegate

My app will receive push notification and basically in the following two functions which are in the AppDelegate.m file, I would like to launch or load a tab in my app when the user receives the push notification. I have several tabs on the app but would like to show one of them.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Any help is appreciated.