Skip to content

Instantly share code, notes, and snippets.

View ysam12345's full-sized avatar

yochien ysam12345

  • Taipei, Taiwan
View GitHub Profile
//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()
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)
{
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)
}
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)
@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()
//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))
}
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
void setup() {
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
int switchStatus;
switchStatus=digitalRead(A0);
if(switchStatus==LOW)
{
if(2>1){//如果括弧合理
digitalWrite(13, HIGH);//該做什麼
}
pinMode(設定腳位, 設定模式);
pinMode(A0, INPUT);//腳位是A0,模式是接收訊號
pinMode(13, OUTPUT);//腳位是13,模式是送出訊號