בגלל ריבוי השפות והמבנה השונה של ביצוע פעולות לפעמים כאשר אתם רוצים לבצע פעולה פשוטה כמו להציג התראה או להציג מספר מתוך טקסט ולא זוכרים את המבנה המדוייק שצריך לבצע את זה, למי זה לא קרה?
בפוסט הזה אני רוצה להציג כמה דוגמאות פשוטות שלא ישאירו אותכם עם המכנסיים למטה.
בפוסט הזה אני רוצה להציג כמה דוגמאות פשוטות שלא ישאירו אותכם עם המכנסיים למטה.
- אז יש פתרונות, אחד מהם זה האתר הזה, אתר מצויין שמסכם כמה פעולות פשוטות בכמה שורות קוד, מאוד שימושי למקרים שהזכרתי מקודם.
- עוד דבר בסיסי שהייתי רוצה להציג לכם זה סרטון, שמדגים ומסביר כיצד לבנות מערכת ניווט באפליקציה שכולל Tab bar ומערכת ניווט משולבת, מאוד שימושי.
- דבר חשוב נוסף זה דגימת מיקום בתוך האפליקציה, דוגמא מצויינת מצאתי באתר שמסביר מצויין כיצד לבצע את זה, אני רוצה להתמקד בדוגמא ולתת כמה הסברים, דוגמה של קוד ניתן להוריד כאן.
- בשלב ראשון יש צורך ליצור מחלקה שמשתמשת ב CLLocationManagerDelegate לפי הדוגמא הבאה:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MyViewController : UIViewController
<CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@end
- בשלב השני להגדיר locationManager שיבקש הרשאות מהמשתמש ולאחר מכן יתחיל לקבל עידכונים של מיקום .
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- בשלב האחרון להגדיר כמה מטודות במחלקה שיקבלו את השינויים במיקום.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
}
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
}
- את הנתון של המיקום יהיה ניתן למצוא בתוך המשתנים lat, longt.
אין תגובות:
הוסף רשומת תגובה