Skip to content

Commit 8e693ff

Browse files
author
UQ Times
committed
標準位置情報サービス・大幅変更位置情報サービス・領域観測のサンプル追加
1 parent d29d174 commit 8e693ff

File tree

6 files changed

+1577
-40
lines changed

6 files changed

+1577
-40
lines changed

CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation.xcodeproj/project.pbxproj

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CE6F6D87156CC07E00D08EB2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE6F6D86156CC07E00D08EB2 /* ViewController.m */; };
1717
CE6F6D8A156CC07E00D08EB2 /* ViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE6F6D88156CC07E00D08EB2 /* ViewController_iPhone.xib */; };
1818
CE6F6D8D156CC07E00D08EB2 /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE6F6D8B156CC07E00D08EB2 /* ViewController_iPad.xib */; };
19+
CE70AE11156FD6E3006F382A /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE70AE10156FD6E3006F382A /* CoreLocation.framework */; };
1920
/* End PBXBuildFile section */
2021

2122
/* Begin PBXFileReference section */
@@ -33,13 +34,15 @@
3334
CE6F6D86156CC07E00D08EB2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
3435
CE6F6D89156CC07E00D08EB2 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPhone.xib; sourceTree = "<group>"; };
3536
CE6F6D8C156CC07E00D08EB2 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPad.xib; sourceTree = "<group>"; };
37+
CE70AE10156FD6E3006F382A /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
3638
/* End PBXFileReference section */
3739

3840
/* Begin PBXFrameworksBuildPhase section */
3941
CE6F6D6C156CC07E00D08EB2 /* Frameworks */ = {
4042
isa = PBXFrameworksBuildPhase;
4143
buildActionMask = 2147483647;
4244
files = (
45+
CE70AE11156FD6E3006F382A /* CoreLocation.framework in Frameworks */,
4346
CE6F6D74156CC07E00D08EB2 /* UIKit.framework in Frameworks */,
4447
CE6F6D76156CC07E00D08EB2 /* Foundation.framework in Frameworks */,
4548
CE6F6D78156CC07E00D08EB2 /* CoreGraphics.framework in Frameworks */,
@@ -69,6 +72,7 @@
6972
CE6F6D72156CC07E00D08EB2 /* Frameworks */ = {
7073
isa = PBXGroup;
7174
children = (
75+
CE70AE10156FD6E3006F382A /* CoreLocation.framework */,
7276
CE6F6D73156CC07E00D08EB2 /* UIKit.framework */,
7377
CE6F6D75156CC07E00D08EB2 /* Foundation.framework */,
7478
CE6F6D77156CC07E00D08EB2 /* CoreGraphics.framework */,
@@ -205,7 +209,10 @@
205209
isa = XCBuildConfiguration;
206210
buildSettings = {
207211
ALWAYS_SEARCH_USER_PATHS = NO;
208-
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
212+
ARCHS = (
213+
armv7,
214+
armv6,
215+
);
209216
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
210217
COPY_PHASE_STRIP = NO;
211218
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -216,11 +223,12 @@
216223
"$(inherited)",
217224
);
218225
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
226+
GCC_THUMB_SUPPORT = NO;
219227
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
220228
GCC_WARN_ABOUT_RETURN_TYPE = YES;
221229
GCC_WARN_UNINITIALIZED_AUTOS = YES;
222230
GCC_WARN_UNUSED_VARIABLE = YES;
223-
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
231+
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
224232
SDKROOT = iphoneos;
225233
TARGETED_DEVICE_FAMILY = "1,2";
226234
};
@@ -230,15 +238,19 @@
230238
isa = XCBuildConfiguration;
231239
buildSettings = {
232240
ALWAYS_SEARCH_USER_PATHS = NO;
233-
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
241+
ARCHS = (
242+
armv7,
243+
armv6,
244+
);
234245
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
235246
COPY_PHASE_STRIP = YES;
236247
GCC_C_LANGUAGE_STANDARD = gnu99;
248+
GCC_THUMB_SUPPORT = NO;
237249
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
238250
GCC_WARN_ABOUT_RETURN_TYPE = YES;
239251
GCC_WARN_UNINITIALIZED_AUTOS = YES;
240252
GCC_WARN_UNUSED_VARIABLE = YES;
241-
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
253+
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
242254
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
243255
SDKROOT = iphoneos;
244256
TARGETED_DEVICE_FAMILY = "1,2";
@@ -251,6 +263,7 @@
251263
buildSettings = {
252264
GCC_PRECOMPILE_PREFIX_HEADER = YES;
253265
GCC_PREFIX_HEADER = "CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation-Prefix.pch";
266+
GCC_THUMB_SUPPORT = NO;
254267
INFOPLIST_FILE = "CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation-Info.plist";
255268
PRODUCT_NAME = "$(TARGET_NAME)";
256269
WRAPPER_EXTENSION = app;
@@ -262,6 +275,7 @@
262275
buildSettings = {
263276
GCC_PRECOMPILE_PREFIX_HEADER = YES;
264277
GCC_PREFIX_HEADER = "CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation-Prefix.pch";
278+
GCC_THUMB_SUPPORT = NO;
265279
INFOPLIST_FILE = "CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation-Info.plist";
266280
PRODUCT_NAME = "$(TARGET_NAME)";
267281
WRAPPER_EXTENSION = app;
@@ -287,6 +301,7 @@
287301
CE6F6D92156CC07E00D08EB2 /* Release */,
288302
);
289303
defaultConfigurationIsVisible = 0;
304+
defaultConfigurationName = Release;
290305
};
291306
/* End XCConfigurationList section */
292307
};

CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation/AppDelegate.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ - (void)dealloc
2424

2525
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2626
{
27+
if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
28+
// アプリの終了中に大幅変更位置情報サービスの通知を受け取った場合
29+
NSLog(@"%s | launchOptions: %@", __PRETTY_FUNCTION__, launchOptions);
30+
31+
UILocalNotification *lc = [[UILocalNotification alloc] init];
32+
lc.alertBody = @"didFinishLaunchingWithOptions";
33+
lc.soundName = UILocalNotificationDefaultSoundName;
34+
[[UIApplication sharedApplication] presentLocalNotificationNow:lc];
35+
[lc release];
36+
// ここでCLLocationManagerを利用する場合はインスタンスを作成しなければならない
37+
}
2738
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
2839
// Override point for customization after application launch.
2940
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
@@ -46,6 +57,15 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
4657
{
4758
// 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.
4859
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
60+
61+
// バックグラウンドでの動作スイッチがオンで、大幅変更位置情報サービスが利用可能ならば、切り替える
62+
if (self.viewController.workInBackgroundSwitch.on) {
63+
if ([CLLocationManager locationServicesEnabled] && [CLLocationManager significantLocationChangeMonitoringAvailable]) {
64+
NSLog(@"%s | stopUpdatingLocation and startMonitoringSignificantLocationChanges", __PRETTY_FUNCTION__);
65+
[self.viewController.locationManager stopUpdatingLocation];
66+
[self.viewController.locationManager startMonitoringSignificantLocationChanges];
67+
}
68+
}
4969
}
5070

5171
- (void)applicationWillEnterForeground:(UIApplication *)application
@@ -56,6 +76,17 @@ - (void)applicationWillEnterForeground:(UIApplication *)application
5676
- (void)applicationDidBecomeActive:(UIApplication *)application
5777
{
5878
// 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.
79+
80+
// 大幅変更位置情報サービスを使っていたのならば停止
81+
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
82+
NSLog(@"%s | stopMonitoringSignificantLocationChanges", __PRETTY_FUNCTION__);
83+
[self.viewController.locationManager stopMonitoringSignificantLocationChanges];
84+
}
85+
// 標準位置情報サービスに切り替える
86+
if ([CLLocationManager locationServicesEnabled]) {
87+
NSLog(@"%s | startUpdatingLocation", __PRETTY_FUNCTION__);
88+
[self.viewController.locationManager startUpdatingLocation];
89+
}
5990
}
6091

6192
- (void)applicationWillTerminate:(UIApplication *)application

CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation-Info.plist

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@
3131
<key>UISupportedInterfaceOrientations</key>
3232
<array>
3333
<string>UIInterfaceOrientationPortrait</string>
34-
<string>UIInterfaceOrientationLandscapeLeft</string>
35-
<string>UIInterfaceOrientationLandscapeRight</string>
3634
</array>
3735
<key>UISupportedInterfaceOrientations~ipad</key>
3836
<array>
3937
<string>UIInterfaceOrientationPortrait</string>
40-
<string>UIInterfaceOrientationPortraitUpsideDown</string>
41-
<string>UIInterfaceOrientationLandscapeLeft</string>
42-
<string>UIInterfaceOrientationLandscapeRight</string>
4338
</array>
4439
</dict>
4540
</plist>

CoreLocationSample-CurrentLocation/CoreLocationSample-CurrentLocation/ViewController.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import <CoreLocation/CoreLocation.h>
1011

11-
@interface ViewController : UIViewController
12+
@interface ViewController : UIViewController <CLLocationManagerDelegate>
13+
14+
@property (nonatomic, retain) CLLocationManager *locationManager;
15+
@property (nonatomic, retain) IBOutlet UILabel *authorizationStatusLabel;
16+
@property (nonatomic, retain) IBOutlet UILabel *distanceFilterLabel;
17+
@property (nonatomic, retain) IBOutlet UILabel *desiredAccuracyLabel;
18+
@property (nonatomic, retain) IBOutlet UILabel *latitudeLabel;
19+
@property (nonatomic, retain) IBOutlet UILabel *longitudeLabel;
20+
@property (nonatomic, retain) IBOutlet UILabel *horizontalAccuracyLabel;
21+
@property (nonatomic, retain) IBOutlet UILabel *altitudeLabel;
22+
@property (nonatomic, retain) IBOutlet UILabel *verticalAccuracyLabel;
23+
@property (nonatomic, retain) IBOutlet UILabel *regionStatusLabel;
24+
@property (nonatomic, retain) IBOutlet UILabel *regionMoniteringLatitudeLabel;
25+
@property (nonatomic, retain) IBOutlet UILabel *regionMoniteringLongitudeLabel;
26+
@property (nonatomic, retain) IBOutlet UILabel *regionMoniteringRadiusLabel;
27+
@property (nonatomic, retain) IBOutlet UILabel *distanceLabel;
28+
@property (nonatomic, retain) IBOutlet UILabel *speedLabel;
29+
@property (nonatomic, retain) IBOutlet UILabel *courseLabel;
30+
@property (nonatomic, retain) IBOutlet UISwitch *workInBackgroundSwitch;
31+
@property (nonatomic, retain) IBOutlet UISwitch *regionMoniteringSwitch;
32+
33+
- (IBAction)regionMoniteringChanged:(UISwitch *)sender;
1234

1335
@end

0 commit comments

Comments
 (0)