This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//switch on | |
var counter = 0 | |
for var i in notificationListData!.data { | |
let center = CLLocationCoordinate2D(latitude: i.data.lat, longitude: i.data.lon) | |
let region = CLCircularRegion(center: center, radius: CLLocationDistance(i.data.radius), identifier: String(counter)) | |
region.notifyOnEntry = true | |
region.notifyOnExit = false | |
let trigger = UNLocationNotificationTrigger(region: region, repeats: false) | |
let content = UNMutableNotificationContent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loadNotificationList() { | |
let url = URL(string: "http://140.121.197.197:3000/getUserNotificationList?facebook_token="+userData!.facebookAccessToken)! | |
let task = URLSession.shared.dataTask(with: url) { (data, response , error) in | |
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .iso8601 | |
if let data = data, let results = try? | |
decoder.decode(NotificationListData.self, from: data) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addPointAndCircleToMapView( lat: Double, lon: Double, radius: Int, content: String) { | |
let newPin = MKPointAnnotation() | |
let coordinate = CLLocationCoordinate2D(latitude: lat,longitude: lon) | |
newPin.coordinate = coordinate | |
newPin.title = content | |
let circle = MKCircle(center: coordinate, radius: CLLocationDistance(radius)) | |
mapView.add(circle) | |
mapView.addAnnotation(newPin) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locationManager = CLLocationManager() | |
if CLLocationManager.authorizationStatus() == .notDetermined { | |
locationManager.requestAlwaysAuthorization() | |
} | |
// 2. 用戶不同意 | |
else if CLLocationManager.authorizationStatus() == .denied { | |
DispatchQueue.main.async(){ | |
let alertController = UIAlertController(title: "定位權限已關閉", message: "如要變更權限,請至 設定 > 隱私權 > 定位服務 開啟", preferredStyle: .alert) | |
let okAction = UIAlertAction(title: "ok", style: .default, handler: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func btnLoginWithFacebookClicked(_ sender: Any) { | |
let fbLoginManager:FBSDKLoginManager = FBSDKLoginManager() | |
fbLoginManager.logIn(withReadPermissions: ["email"], from: self) {(result, error) in | |
if (error == nil){ | |
let fbLoginResult:FBSDKLoginManagerLoginResult = result! | |
if fbLoginResult.grantedPermissions != nil { | |
if(fbLoginResult.grantedPermissions.contains("email")) { | |
self.getFBUserData() | |
self.turnToIndexSreen() | |
//fbLoginManager.logOut() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get notification device token | |
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
let deviceTokenString = deviceToken.reduce("") { | |
return $0 + String(format: "%02x", $1) | |
} | |
print(deviceTokenString) | |
//save device token | |
DeviceToken.save(deviceToken: DeviceToken(token: deviceTokenString)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
//Push Notification Authorization | |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in | |
} | |
UIApplication.shared.registerForRemoteNotifications() | |
// 讓 App 在前景狀態下收到通知 | |
UNUserNotificationCenter.current().delegate = self |
NewerOlder