ãswiftãiOSã§Pushéç¥ãååãå®è£
äºåæºå
- Apple Developer Programã®ç»é²
- Pushéç¥ã«å¿ è¦ãªè¨¼ææ¸ã®ä½ãæ¹ï¼ä¸å¯§ã«æ¸ããã¦ãã¾ããï¼
Xcodeããã¸ã§ã¯ãã®è¨å®
- ããã¸ã§ã¯ãã«ã¯äºåæºå2ã§è¨å®ãããã³ãã«ãè¨å®ãã¦ãã ãã
- TARGETã®è¨å®ã§+CapabilityããPush Notificationsã追å ãã¦ãã ãã
AppDelegateã®å®è£
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) ã«ããã·ã¥éç¥ã®å©ç¨è¨±å¯ãè¨è¼ãã¾ãã
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // ããã·ã¥éç¥ã®å©ç¨è¨±å¯ UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in guard granted else { return } DispatchQueue.main.async { // ããã·ã¥éç¥ã®ç»é² UIApplication.shared.registerForRemoteNotifications() } } return true }
- ããã·ã¥éç¥ã®ç»é²ãæåããå ´åã®CallBacké¢æ°ãè¨è¿°
// ããã·ã¥éç¥ã®ç»é²ãæåããå ´åCallBackããã func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let token = deviceToken.map { String(format: "%.2hhx", $0) }.joined() NSLog("DeviceToken: \(token)") }
- ããã·ã¥éç¥ã®ç»é²ã失æããå ´åã®CallBacké¢æ°ãè¨è¿°
// ããã·ã¥éç¥ã®ç»é²ã失æããå ´åCallBackããã func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { NSLog("ã¨ã©ã¼: \(error)") }
ã¢ããªãå®æ©ã«ã¤ã³ã¹ãã¼ã«ãã¦ããã¤ã¹ãã¼ã¯ã³ãåå¾
- å®æ©ãæ¥ç¶ãã¢ããªãã¤ã³ã¹ãã¼ã«ããã¨è¨±å¯ãã¤ã¢ãã°ã表示ãããã®ã§è¨±å¯ãã
- æåããã¨Xcodeã®ã³ã³ã½ã¼ã«ã«ããã¤ã¹ãã¼ã¯ã³ã表示ãããã®ã§ã¡ã¢ãã
Pushéç¥ããã¹ãéä¿¡
- ãã¹ããã¼ã«(ãã¡ãã使ã£ã¦ã¿ã¾ããã)
- å種å¤ãå ¥ãã¦Pushãã¿ã³ã§éä¿¡ããã¾ãã
æåã¯æéããããã®ã§å°ãå¾
ã£ã¦ãã ãã
- åä¿¡ã§ãã¾ãã
- ä¾¡æ ¼: 3380 å
- 楽天ã§è©³ç´°ãè¦ã