Skip to content

Instantly share code, notes, and snippets.

@amazedkoumei
Created December 4, 2013 03:04
Show Gist options
  • Save amazedkoumei/7781674 to your computer and use it in GitHub Desktop.
Save amazedkoumei/7781674 to your computer and use it in GitHub Desktop.
pushtest using parse.com
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
self.register_push_notifications(application)
self.configure_parse_service(launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = HelloViewController.new
@window.makeKeyAndVisible
true
end
def application(application, didFailToRegisterForRemoteNotificationsWithError:error)
if (error.code == 3010)
App.alert("Push notifications don't work in the simulator!")
else
App.alert("didFailToRegisterForRemoteNotificationsWithError: #{error.code}, #{error.domain}, #{error.userInfo}")
end
end
def register_push_notifications(application)
application.registerForRemoteNotificationTypes(
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)
end
def configure_parse_service(launchOptions)
# see https://parse.com/apps/pushtest--177/edit#app_keys
Parse.setApplicationId(
"Parse.com の Application Id",
clientKey:"Parse.com の client key",
)
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
end
# callback of register_push_notifications
# see https://www.parse.com/tutorials/ios-push-notifications
def application(application, didRegisterForRemoteNotificationsWithDeviceToken:newDeviceToken)
# Store the deviceToken in the current installation and save it to Parse.
currentInstallation = PFInstallation.currentInstallation()
currentInstallation.setDeviceTokenFromData(newDeviceToken)
currentInstallation.saveInBackground()
end
def application(application, didReceiveRemoteNotification:userInfo)
PFPush.handlePush(userInfo)
end
end
source 'https://rubygems.org'
gem 'rake'
gem 'motion-cocoapods'
gem "bubble-wrap", :require => "bubble-wrap/all"
# -*- coding: utf-8 -*-
class HelloViewController < UIViewController
def viewDidLoad
super
view.backgroundColor = UIColor.blueColor
end
end
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
begin
require 'bundler'
Bundler.require
rescue LoadError
end
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'pushtest'
app.identifier = "自分の app indentifier"
# Parse.com の依存ライブラリ
# see https://parse.com/apps/quickstart_push#ios/native/existing
app.frameworks += [
"AudioToolbox",
"CFNetwork",
"CoreGraphics",
"CoreLocation",
"MobileCoreServices",
"QuartzCore",
"Security",
"StoreKit",
"SystemConfiguration"
]
app.libs += ["/usr/lib/libz.dylib"]
# Parse.com SDK
app.vendor_project(
'vendor/Parse.framework',
:static,
:products => ['Parse'],
:headers_dir => 'Headers'
)
# Parse.com SDK が依存してる Objective-C ライブラリ
app.pods do
pod 'Facebook-iOS-SDK'
end
app.development do
# Provisioning Profile のパス
# Provisioning Profile の作成方法は
# → https://www.parse.com/tutorials/ios-push-notifications
app.provisioning_profile = ""
# この行がないと 'aps-environment' error が返る
# TODO: at release, see http://kametaro.wordpress.com/2011/09/21/appstore%E3%81%8B%E3%82%89%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%97%E3%81%9F%E3%82%A2%E3%83%97%E3%83%AA/
app.entitlements['aps-environment'] = 'development'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment