Thursday, May 19, 2016

How to take screenshot automatically/ periodically on Mac by script

first, create folder and .sh file by terminal
(on this sample, "screenshot" and "Screencapture.sh")

$ cd
$ mkdir screenshot
$ cd screenshot

$ touch Screencapture.sh


Second,
create shell script


#!/bin/bash

/usr/sbin/screencapture -m -C -T0 -x ~/screenshot/capture_`date +%Y%m%d%H%M`.png



Next, permission.
$ chmod +x Screencapture.sh


Then, open your editor and copy and paste.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

    <key>Label</key>

    <string>com.example.app</string>

    <key>ProgramArguments</key>

    <array>

        <string>/Users/xxxxx(username)/Screenshot.sh</string>

    </array>

    <key>StartInterval</key>

    <integer>300</integer>

</dict>

</plist>


Great, save this file as "com.example.app.plist" and locate to "/Library/LaunchDaemons"

then, run.
launchctl load -w /Library/LaunchDaemons/com.example.app.plist

You will see screen shot each 5 min.

reference
http://www.splinter.com.au/using-launchd-to-run-a-script-every-5-mins-on/




How to solve an error " Invalid or missing service identifier" on launchd


When I tried to start plist file by
launchctl load -w /Library/LaunchDaemons/com.example.app.plist

it shows:
/Library/LaunchDaemons/com.example.app.plist: Invalid or missing service identifier


check the plist file.
<key>label</key>

this was the problem.


the Label must be upper capital like ;
<key>Label</key>


then run correctly.

Sunday, May 1, 2016

how to zoom-in on the Mapkit by swift

 @IBAction func zoomInMap (sender: AnyObject) {
        let userLocation = mapView.userLocation
        let region = MKCoordinateRegionMakeWithDistance(userLocation.location!.coordinate, 800, 800)
        mapView.setRegion(region,animated:true)

    }


connect with action "zoomInMap"
set the parameter in MKCoordinateRegionMakeWithDistance property. 

How to solve "could not insert new outlet connection could not find any information for the class named viewcontroller"

It happens when I connect outlet using assistant editor on Xcode.

Just quit Xcode and restart as internet shows.
 then,,,, doesn't work.

Eventually it works when I shut down mac and restart. 


Thursday, September 10, 2015

how to solve The model used to open the store is incompatible with the one used to create the store error on swift

It happened when I changed the model after several struggling during app working ( using old model)

how to solve.
I changed the simulator from 5s to 5. 
it works.


Friday, August 28, 2015

How to make an notification on swift

to make a notification app is simple.




1, add code on ViewContrller.swift like this.


import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        var localNotification:UILocalNotification = UILocalNotification()
        localNotification.alertAction = "Testing notifications"
        localNotification.alertBody = "hello world! "
        localNotification.fireDate = NSDate(timeIntervalSinceNow: 30)
        UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}



2, add code on AppDelegate.swift like this.

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound |
            UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories:nil))
        
        return true
    }


3, run your simulator. Don't forget to waiting at home screen.

I referred here
https://www.topcoder.com/blog/notifications-in-ios-8-using-swift/

how to fix an error of notification " time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = user info = (null)} with an alert but haven't received permission from the user to display alerts by swift

When I tried to make a notification, I encountered this error showing on debug area.

(shows your timezone)  time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = (shows your fire date)  user info = (null)} with an alert but haven't received permission from the user to display alerts

It means iOS8 needs user's permission.

How to solve;

add code in func application( application : ---- ) on AppDelegate.swift like following.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound |
            UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories:nil))
        
        return true

    }

FYI
http://stackoverflow.com/questions/24100313/ask-for-user-permission-to-receive-uilocalnotifications-in-ios-8