{"id":18271804,"url":"https://github.com/jpoz/APNS","last_synced_at":"2025-04-05T02:30:43.855Z","repository":{"id":608198,"uuid":"245364","full_name":"jpoz/APNS","owner":"jpoz","description":"An Apple Push Notification Service gem","archived":true,"fork":false,"pushed_at":"2017-07-20T23:40:34.000Z","size":350,"stargazers_count":540,"open_issues_count":37,"forks_count":195,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-03-21T18:17:10.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpoz.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-07-07T16:54:41.000Z","updated_at":"2025-02-07T06:42:28.000Z","dependencies_parsed_at":"2022-08-16T10:31:15.527Z","dependency_job_id":null,"html_url":"https://github.com/jpoz/APNS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpoz%2FAPNS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpoz%2FAPNS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpoz%2FAPNS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpoz%2FAPNS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpoz","download_url":"https://codeload.github.com/jpoz/APNS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247279276,"owners_count":20912856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:39:31.747Z","updated_at":"2025-04-05T02:30:43.151Z","avatar_url":"https://github.com/jpoz.png","language":"Ruby","funding_links":[],"categories":["etc"],"sub_categories":[],"readme":"h1. APNS\n\na gem for the Apple Push Notification Service.\n\nh2. Install\n\nsudo gem install apns\n\nh2. Setup:\n\nConvert your certificate\n\nIn Keychain access export your certificate as a p12. Then run the following command to convert it to a .pem\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nAfter you have your .pem file. Set what host, port, certificate file location on the APNS class:\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    APNS.host = 'gateway.push.apple.com' \n    # gateway.sandbox.push.apple.com is default\n\n    APNS.pem  = '/path/to/pem/file'\n    # this is the file you just created\n    \n    APNS.port = 2195 \n    # this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can.\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nh2. Example (Single notification):\n\nThen to send a push notification you can either just send a string as the alert or give it a hash for the alert, badge and sound.\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    device_token = '123abc456def'\n\n    APNS.send_notification(device_token, 'Hello iPhone!' )\n\n    APNS.send_notification(device_token, :alert =\u003e 'Hello iPhone!', :badge =\u003e 1, :sound =\u003e 'default')\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nh2. Example (Multiple notifications):\n\nYou can also send multiple notifications using the same connection to Apple:\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    device_token = '123abc456def'\n\n    n1 = APNS::Notification.new(device_token, 'Hello iPhone!' )\n\n    n2 = APNS::Notification.new(device_token, :alert =\u003e 'Hello iPhone!', :badge =\u003e 1, :sound =\u003e 'default')\n    \n    APNS.send_notifications([n1, n2])\n  \u003c/code\u003e\n\u003c/pre\u003e\n\n\nh2. Send other info along with aps\n\nYou can send other application specific information as well.\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    APNS.send_notification(device_token, :alert =\u003e 'Hello iPhone!', :badge =\u003e 1, :sound =\u003e 'default',\n                                         :other =\u003e {:sent =\u003e 'with apns gem'})\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nThis will add the other hash to the same level as the aps hash:\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    {\"aps\":{\"alert\":\"Hello iPhone!\",\"badge\":1,\"sound\":\"default\"},\"sent\":\"with apns gem\"}\n  \u003c/code\u003e\n\u003c/pre\u003e\n\n\nh2. Getting your iPhone's device token\n\nAfter you setup push notification for your application with Apple. You need to ask Apple for you application specific device token.\n\nh3. ApplicationAppDelegate.m\n\n\u003cpre\u003e\n  \u003ccode\u003e\n    - (void)applicationDidFinishLaunching:(UIApplication *)application \n    {    \n        // Register with apple that this app will use push notification\n        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | \n          UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];\n\n        // Your app startup logic...\n        return YES;\n    }\n\n    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken \n    {\n        // Convert the binary data token into an NSString (see below for the implementation of this function)\n        NSString *deviceTokenAsString = stringFromDeviceTokenData(deviceToken);\n\n        // Show the device token obtained from apple to the log\n        NSLog(@\"deviceToken: %@\", deviceTokenAsString);\n    }\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nh3. stringFromDeviceTokenData function\n\nThis snippet comes from \"this stackoverflow post's anwser\":http://stackoverflow.com/a/1990880/855846.\n\u003cpre\u003e\n  \u003ccode\u003e\n    NSString* stringFromDeviceTokenData(NSData *deviceToken)\n    {\n      const char *data = [deviceToken bytes];\n      NSMutableString* token = [NSMutableString string];\n      \n      for (int i = 0; i \u003c [deviceToken length]; i++) {\n        [token appendFormat:@\"%02.2hhX\", data[i]];\n      }\n      \n      return [[token copy] autorelease];\n    }\n  \u003c/code\u003e\n\u003c/pre\u003e\n\nFor more information on Apple Push Notifications you can see Apple Developer Documentation \"here\":http://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpoz%2FAPNS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpoz%2FAPNS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpoz%2FAPNS/lists"}