static void window_unload(Window *window) { numOfNotifications = 0; nw_ui_unload(); #ifdef PBL_COLOR if (bitmapReceivingBuffer != NULL) { free(bitmapReceivingBuffer); bitmapReceivingBuffer = NULL; } if (notificationBitmap != NULL) { gbitmap_destroy(notificationBitmap); notificationBitmap = NULL; } #endif #ifdef PBL_MICROPHONE if (dictationSession != NULL) dictation_session_destroy(dictationSession); #endif accel_tap_service_unsubscribe(); bluetooth_connection_service_unsubscribe(); tick_timer_service_unsubscribe(); window_destroy(window); if (main_noMenu && config_dontClose) { closeApp(); } if (main_noMenu) closingMode = true; for (int i = 0; i < NOTIFICATION_SLOTS; i++) { destroy_notification(notificationData[i]); } }
int push_send(PushServer* apns, const char *device_token, const char* alert, const char* custom, int badge) { APNS_Payload* payload = NULL; APNS_Item* item; uint32_t id; char* message; if (device_token == NULL) { LM_ERR("Cannot start push, device token is NULL\n"); return -1; } if (alert == NULL) { LM_ERR("Cannot start push, alert is NULL\n"); return -1; } LM_DBG("token %s\n", device_token); APNS_Notification* notification = create_notification(); if (notification == NULL) { LM_ERR("Cannot create notification\n"); return -1; } payload = calloc(1, sizeof(APNS_Payload)); if (payload == NULL) { LM_ERR("Cannot create payload\n"); destroy_notification(notification); return -1; } payload->alert = strdup(alert); payload->custom_param = (custom == NULL) ? NULL : strdup(custom); payload->badge = badge; item = create_item(payload, PUSH_MAX_PRIO); if (item == NULL) { LM_ERR("Cannot create item\n"); destroy_notification(notification); destroy_payload(payload); return -1; } str2bin(device_token, item->token); id = item->identifier = get_notification_id(); if (-1 == notification_add_item(notification, item)) { LM_ERR("Cannot add item, return....\n"); destroy_notification(notification); destroy_payload(payload); return -1; } LM_DBG("item successfuly added, make a message\n"); message = make_push_msg(notification); if (message == NULL) { LM_DBG("make_push_msg failed, destroy it\n"); destroy_notification(notification); LM_DBG("Return -1\n"); return -1; } { char *buf; bin2str(message, notification->length, &buf); LM_DBG("Sending data to apns: [%s], length %d\n", buf, notification->length); free(buf); } if (-1 == send_push_data(apns, message, notification->length)) { LM_ERR("Push sending failed\n"); } LM_DBG("OK\n"); // free(message); add_push_to_queue(id, message, notification->length); LM_DBG("Destroy\n"); destroy_notification(notification); LM_DBG("Success\n"); return 1; }