Trying to get location updates in background not working - iphone

Hello everyone I am trying to get a location update when my app is in background. But the code below does not seems to work. The IF statement is never true. I have also set the necessary keys in the info.plist files. I am running the code in iphone 3GS and ipad 3.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customizatio-n after application launch.
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
// create a new manager and start checking for sig changes
locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
[locManager startMonitoringSignificantLocationChanges];
return YES;
}

Related

Linking facebook sdk to ios

I have a dead line and dont know what to do with that. IM tryin to use react-native-fbsdk with firebase on and wanted to link the sdk to ios. Everything is good but this function:
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
// Add any custom logic here.
return YES;
Im trying to put this here:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:#"tzawajna"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
// Add any custom logic here.
return YES;
}
And Its giving an error of
use of undeclared identifier FBSDKApplicationDelegate
What should I do.
Thanks
Check whether In your application:openURL:options implementation ( or for any other method in the file), the parameter is named app and not application.
You can either change the parameter name in the method signature to application:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
This error can be caused because of the difference in the parameter of such method.

Store data after adding items to array

I have an array that you can add items to. Though when I exit the app the records are not saved. How would I do this.
Here is my appdelgate file becausde that is where my NSMutableArray is held
AppDelegate.m:
#import "LSAppDelegate.h"
#import "LSViewController.h"
#import "Patient.h"
#import "PRViewController.h"
#implementation LSAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Patient *patient = [[Patient alloc]init];
patient.patientName = #"Patient Name";
patient.patientSurname = #"Patient Surname";
patient.patientDoB = #"Patient Date of Birth";
patient.patientHomeNumber = #"Patient Home No";
patient.patientMobileNumber = #"Patient Mobile No";
patient.patientEmail = #"Patient Email Address";
patient.patientAddress = #"Patient Address";
patient.patientPicture = [UIImage imageNamed:#"patientPicture.jpg"];
// Treatments
patient.treatmentName = #"Treatment Name";
patient.treatmentDate = #"Treatment Date";
patient.treatmentType = #"Treatment Type";
self.patients = [[NSMutableArray alloc]
initWithObjects:patient, nil];
// Override point for customization after application launch.
self.viewController = [[LSViewController alloc] initWithNibName:#"LSViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[[UINavigationBar appearance] setTintColor:[UIColor brownColor]];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
- (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
{
}
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
#end
so far all i've got is:
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
please say if you want more code snippets or files.
To preserve the data, you write it to a file on disk and then load that file when the application is started again.
This is how I have done it in my apps.
Create your array and save it to NSdictonary object
Then store your NSDictonary to your apps documents directory.
When your app launches then find your NSDictonary file object and read the array out of it.
The advantage of using NSDictonary is that you can store multiple arrays (in case you are storing multiple patient info).
Here are some sample answers to get you started.
How to store an NSArray in an NSDictionary?
is it possible to save NSMutableArray or NSDictionary data as file in iOS?
How can we store into an NSDictionary? What is the difference between NSDictionary and NSMutableDictionary?

Integration of Dropbox in iPhone application error 400

I am using the great source code called GSDropboxDemoApp which nicely integrate the Dropbox in the application. However, after linked to the app to Dropbox, it gives error in loading folder contents. Below are the codes
I have already edited the info.plist
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#warning Potentially incomplete method implementation. Fill in your Dropbox credentials!
#warning NB: you must also update the URL scheme listed under the CFBundleURLTypes key in GSDropboxDemoApp-Info.plist
NSString *dropboxAppKey = #"sxxxxxxxxxx";
NSString *dropboxAppSecret = #"cxxxxxxxxx";
NSString *dropboxRoot = #"kDBRootAppFolder"; // either kDBRootAppFolder or kDBRootDropbox
DBSession* dbSession = [[DBSession alloc] initWithAppKey:dropboxAppKey
appSecret:dropboxAppSecret
root:dropboxRoot];
[DBSession setSharedSession:dbSession];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[GSViewController alloc] initWithNibName:#"GSViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(#"App linked to Dropbox successfully");
} else {
NSLog(#"App not linked to Dropbox!");
}
return YES;
}
return NO;
}
Error Message
GSDropboxDemoApp[4674:907] [WARNING] DropboxSDK: error making request to /1/metadata/kDBRootAppFolder - (400) Expected a root of either 'dropbox' or 'sandbox', got 'kDBRootAppFolder'
You should be using a constant, like so:
NSString *dropboxRoot = kDBRootAppFolder; // either kDBRootAppFolder or kDBRootDropbox
Constants are used so that you don't need to worry about the actual value itself.
And for those of us (in the future that stumble across this question) getting the same error using ruby motion, it needs to be:
dropboxRoot = KDBRootAppFolder # Capital K

Can't see a heatmap using Heatma.ps SDK

I successfully installed heatma.ps SDK (https://heatma.ps) in my iPhone application. It tracks all the touches and gestures, but I can't view a heatmap when I shake my device. Any idea why? There is no log, it just doesn't show up.
This is how I setup my heatmaps object.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
heatmaps = [[Heatmaps alloc] init];
heatmaps.showDebug = YES;
[heatmaps start];
//...
}
To see heatmaps you need to set showMenu property of heatmaps object to YES
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
heatmaps = [[Heatmaps alloc] init];
heatmaps.showDebug = YES;
heatmaps.showMenu = YES;
[heatmaps start];
//...
}
Watch the following screencast: "Viewing heatmaps"

iPhone didFinishLaunchingWithOptions Method

So i'm trying to use this method to load a certain theme based on what the user chose in the settings bundle. When I insert NSLog it will load the default them (Modern Theme), but it will never change to the Pink Theme.
Is this method loaded every time the app is launched, even if the app is still running in the background.
Otherwise, where else could I do this, if I want to use the settings bundle.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *userDefaultsDefaults = [NSDictionary dictionaryWithObjectsAndKeys: #"Modern Theme", #"theme", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsDefaults];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
theme =[defaults objectForKey:#"theme"];
NSLog(#"%#", theme);
if ([theme isEqualToString:#"Modern Theme"]) {
viewController = [[viewTwo alloc] initWithNibName:#"viewTwo" bundle:nil];
}
else {
viewController = [[viewOne alloc] initWithNibName:#"viewOne" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Have you tried putting your code in applicationDidBecomeActive:? That one is guaranteed to be called whether on the initial launch or resuming from the background.
Reference docs.
The method
- (void)applicationWillResignActive:(UIApplication *)application
is fired when the app is resumed from the background.
I'd nearly load the theme in the ViewController's
-(void)viewDidAppear:(BOOL)animated
method.