Esempio n. 1
0
    def send_ios(self, story, user, usersub):
        if not self.is_ios: return

        apns = APNs(
            use_sandbox=True,
            cert_file='/srv/newsblur/config/certificates/aps_development.pem',
            key_file='/srv/newsblur/config/certificates/aps_development.pem')

        tokens = MUserNotificationTokens.get_tokens_for_user(self.user_id)
        title, subtitle, body = self.title_and_body(story, usersub)
        image_url = None
        if len(story['image_urls']):
            image_url = story['image_urls'][0]
            # print image_url

        for token in tokens.ios_tokens:
            logging.user(
                user, '~BMStory notification by iOS: ~FY~SB%s~SN~BM~FY/~SB%s' %
                (story['story_title'][:50], usersub.feed.feed_title[:50]))
            payload = Payload(alert={
                'title': title,
                'subtitle': subtitle,
                'body': body
            },
                              category="STORY_CATEGORY",
                              mutable_content=True,
                              custom={
                                  'story_hash': story['story_hash'],
                                  'story_feed_id': story['story_feed_id'],
                                  'image_url': image_url,
                              })
            apns.gateway_server.send_notification(token, payload)
Esempio n. 2
0
    def send_ios(self, story, user, usersub):
        if not self.is_ios: return

        apns = APNs(use_sandbox=False,
                    cert_file='/srv/newsblur/config/certificates/aps.pem',
                    key_file='/srv/newsblur/config/certificates/aps.p12.pem',
                    enhanced=True)

        tokens = MUserNotificationTokens.get_tokens_for_user(self.user_id)
        notification_title_only = is_true(
            user.profile.preference_value('notification_title_only'))
        title, subtitle, body = self.title_and_body(story, usersub,
                                                    notification_title_only)
        image_url = None
        if len(story['image_urls']):
            image_url = story['image_urls'][0]
            # print image_url

        def response_listener(error_response):
            logging.user(
                user,
                "~FRAPNS client get error-response: " + str(error_response))

        apns.gateway_server.register_response_listener(response_listener)

        for token in tokens.ios_tokens:
            logging.user(
                user, '~BMStory notification by iOS: ~FY~SB%s~SN~BM~FY/~SB%s' %
                (story['story_title'][:50], usersub.feed.feed_title[:50]))
            payload = Payload(alert={
                'title': title,
                'subtitle': subtitle,
                'body': body
            },
                              category="STORY_CATEGORY",
                              mutable_content=True,
                              custom={
                                  'story_hash': story['story_hash'],
                                  'story_feed_id': story['story_feed_id'],
                                  'image_url': image_url,
                              })
            apns.gateway_server.send_notification(token, payload)